2016-08-29 46 views
1

我试图对货物maven2插件运行一些功能测试。这些测试在本地tomcat服务器上运行时没有使用货物maven2插件启动。该插件本身成功引导,但是当我运行测试,他们返回与下面的跟踪500错误代码:ClassNotFoundException:使用货物maven2插件运行测试时的oracle.jdbc.OracleDriver

Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.OracleDriver' 
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429) 
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371) 
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) 

... 109 more 
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver 
at java.lang.ClassLoader.findClass(ClassLoader.java:531) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
at persistence.spi.hibernate.TransformingClassLoader.loadClass(TransformingClassLoader.java:46) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:14 

我已经加入我的POM ojdbc 6罐子和排除引用ojdbc 5和ojdbc 14

这里是我的货物配置:

 <plugin> 
     <groupId>org.codehaus.cargo</groupId> 
     <artifactId>cargo-maven2-plugin</artifactId> 
     <version>1.4.14</version> 
     <configuration> 
      <container> 
       <containerId>tomcat7x</containerId> 
       <type>installed</type> 
       <zipUrlInstaller> 
       <url>http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70.zip</url> 
       <downloadDir>${project.build.directory}/downloads</downloadDir> 
       <extractDir>${project.build.directory}/extracts</extractDir> 
       </zipUrlInstaller> 
       <systemProperties> 
       <java.io.tmpdir>target/tmp</java.io.tmpdir> 
       </systemProperties> 
       <output>${project.build.directory}/cargo-container.log</output> 
       <log>${project.build.directory}/cargo.log</log> 
      </container> 
      <deployables> 
       <deployable> 
       <groupId>x.rest</groupId> 
       <artifactId>x-war</artifactId> 
       <type>war</type> 
       </deployable> 
      </deployables> 
      <configuration> 
       <type>standalone</type> 
       <home>${project.build.directory}/tomcat7x/container</home> 
       <properties> 
       <cargo.tomcat.ajp.port>9414</cargo.tomcat.ajp.port> 
            <cargo.servlet.port>9484</cargo.servlet.port> 
       <cargo.rmi.port>9496</cargo.rmi.port> 
       <cargo.logging>high</cargo.logging> 
       <war>${project.build.directory}/x-war.war</war> 
       <!-- This section was added by me but didn't fix the problem --> 
       <cargo.datasource.datasource> 
        cargo.datasource.jndi=jdbc/DB| 
        cargo.datasource.type=javax.sql.DataSource| 
        cargo.datasource.driver=oracle.jdbc.OracleDriver| 
        cargo.datasource.url=jdbc:oracle:thin:abc/[email protected]:22:node1| 
        cargo.datasource.username=abc| 
        cargo.datasource.password=abc 
       </cargo.datasource.datasource> 
       </properties> 
       <configfiles> 
       <configfile> 
        <file>${project.basedir}/src/test/resources/war-dependencies/stable-dev/context.xml</file> 
        <todir>conf</todir> 
        <tofile>context.xml</tofile> 
       </configfile> 
       </configfiles> 
       <files> 
       <file> 
        <file>${project.basedir}/src/test/resources/war-dependencies/stable-dev/service.keystore</file> 
        <todir>shared/classes</todir> 
       </file> 
       </files> 
      </configuration> 
     </configuration> 
     <executions> 
      <!-- The executions here deal only with INTEGRATION-TEST phase. We are NOT hitting REST Service via tests in the TEST phase. We need to be assured that our container is already 
       up and running. So cargo is started in PRE-INTEGRATION-TEST phase. --> 
      <execution> 
       <id>start-container</id> 
       <phase>pre-integration-test</phase> 
       <goals> 
       <goal>stop</goal> 
       </goals> 
      </execution> 
     <!-- <execution> 
       <id>stop-container</id> 
       <phase>post-integration-test</phase> 
       <goals> 
       <goal>stop</goal> 
       </goals> 
      </execution>--> 
     </executions> 
    </plugin> 

我是网络服务世界的新手,所以任何建议/指针将不胜感激。可能是我在某处丢失了一些配置?

回答

0

明白了上班。我不得不在容器部分添加ojdbc6作为依赖项。

0

你在tomcat上没有例外的原因可能是由于Tomcat的lib文件夹中现有的ojdbc6.jar文件。

但是,由于法律问题,无法在公用Maven存储库中找到oracle jdbc驱动程序jar文件。

这里是让Oracle JDBC驱动程序从Maven仓库

Get Oracle JDBC drivers from the Oracle Maven Repository - NetBeans, Eclipse & Intellij

官方指令还有另一种简单而直接的解决方案。

通过复制在本地驱动器的jar文件,打开命令提示符下直接安装JAR文件到本地库,转到jar文件的当前目录并执行以下命令

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dpackaging=jar -Dversion=11.2.0.4.0 -Dfile=ojdbc6.jar -DgeneratePom=true 
+0

感谢您的建议,但我可以在我的测试项目中看到ojdbc6 -11.2.0.3作为引用库的一部分。这对货物来说应该不够吗? – linuxNoob

相关问题