Search code examples
javaintellij-ideaojdbccucumber-java

test script fails when triggered using jenkins gives java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver error message


I have added a ojdbc14 jar file to gradle project in Intellij, my test scripts including db validations runs fine when triggered the test cases using the run option in Intellij. But the same test script fails when triggered through the CI using jenkins and gives me the below error

Feature: 3D secure code scenarios
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at util.OracleDBService.createDriver(OracleDBService.java:88)
    at util.OracleDBService.openConnection(OracleDBService.java:56)
    at util.OracleDBService.executeQuery(OracleDBService.java:13)
    at pages.DBListOfQuery.getOrderStatusFromDB(DBListOfQuery.java:67)
    at steps.FlowScenarioSteps.verify_the_order_placed_for_order_id_and_validate_order_xml(FlowScenarioSteps.java:226)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at cucumber.runtime.Utils$1.call(Utils.java:34)
    at cucumber.runtime.Timeout.timeout(Timeout.java:13)
    at cucumber.runtime.Utils.invoke(Utils.java:30)

My project.iml file includes jdbc library

 <library>
        <CLASSES>
          <root url="jar://$USER_HOME$/Downloads/ojdbc14.jar/ojdbc14.jar!/" />
        </CLASSES>
        <JAVADOC />
        <SOURCES />
      </library>

Solution

  • This is because Jenkins doesn't know nothing about ojdbc14.jar. When Jenkins fires job in this example want to compile project, tests some classes and so on, it must know about provided libraries.

    I have no idea how Jenkins is configured in your company or on your local computer but you need to add manually this ojdbc14.jar to its local repository. Local repository can for example be handled by maven or gradle.

    So in this case you need to configure Jenkins to use gradle and add ojdbc14.jar to gradle local repository.