jmeterjtds

Getting error on oracle and jtds driver while executing jmeter script using maven project


I have a jmx script which have JDBC request for connecting to both oracle and sql server. I am using maven project for execution of jmx script and I have already declared dependency for both of these servers in pom.xml. But I continue to get the error for both of these drivers.

maven dependencies:

    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.oracle.jdbc</groupId>
        <artifactId>ojdbc8</artifactId>
        <version>12.2.0.1</version>
    </dependency>

Error Oracle DB:

[INFO] Cannot load JDBC driver class 'oracle.jdbc.OracleDriver'
[INFO] java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
[INFO]  at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
[INFO]  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
[INFO]  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[INFO]  at org.apache.commons.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2197)
[INFO]  at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2104)
[INFO]  at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1563)
[INFO]  at org.apache.jmeter.protocol.jdbc.config.DataSourceElement$DataSourceComponentImpl.getConnection(DataSourceElement.java:334)
[INFO]  at org.apache.jmeter.protocol.jdbc.config.DataSourceElement.getConnection(DataSourceElement.java:193)
[INFO]  at org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler.sample(JDBCSampler.java:79)
[INFO]  at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622)
[INFO]  at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546)
[INFO]  at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486)
[INFO]  at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
[INFO]  at java.base/java.lang.Thread.run(Thread.java:834)

Error: (SQL server)

[INFO] Cannot load JDBC driver class 'net.sourceforge.jtds.jdbc.Driver'
[INFO] java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
[INFO]  at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
[INFO]  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
[INFO]  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[INFO]  at org.apache.commons.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2197)
[INFO]  at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2104)
[INFO]  at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1563)
[INFO]  at org.apache.jmeter.protocol.jdbc.config.DataSourceElement$DataSourceComponentImpl.getConnection(DataSourceElement.java:334)
[INFO]  at org.apache.jmeter.protocol.jdbc.config.DataSourceElement.getConnection(DataSourceElement.java:193)
[INFO]  at org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler.sample(JDBCSampler.java:79)
[INFO]  at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622)
[INFO]  at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546)
[INFO]  at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486)
[INFO]  at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
[INFO]  at java.base/java.lang.Thread.run(Thread.java:834)

Solution

  • This is not correct way for adding dependencies via JMeter Maven plugin, you need to specify the external libraries under <configuration> section like:

    <configuration>
        <testPlanLibraries>
            <artifact>net.sourceforge.jtds:jtds:1.3.1</artifact>
            <artifact>com.oracle.jdbc:ojdbc8:12.2.0.1</artifact>
        </testPlanLibraries>
    </configuration>
    

    Full pom.xml just in case:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.example</groupId>
        <artifactId>jmeter</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>LATEST</version>
    
                    <executions>
                        <!-- Run JMeter tests -->
                        <execution>
                            <id>jmeter-tests</id>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                        </execution>
                        <!-- Fail build on errors in test -->
                        <execution>
                            <id>jmeter-check-results</id>
                            <goals>
                                <goal>results</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <testPlanLibraries>
                            <artifact>net.sourceforge.jtds:jtds:1.3.1</artifact>
                            <artifact>com.oracle.jdbc:ojdbc8:12.2.0.1</artifact>
                        </testPlanLibraries>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    More information: