开发者

Running test from Maven fails and stops building the jar

I am trying to build a jar using maven , this jar was build using ant.

When I run tests from maven I got an:

ERROR org.hibernate.tool.hbm2ddl.SchemaValidator could not complete schema validation 
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'net.sourceforge.jtds.jdbc.Driver'

which comes from:

Caused by: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
at java.net.URLClassLoader$1.run(开发者_开发百科URLClassLoader.java:200)

When i build the jar without running test, it is built but it's missing some .class and .properties files, so this jar is not running as expected.

To be more concise, in my jar are missing compiled files which should come from /test folder.

Could be some wrong dependencies added in my pom.xml?


I get a (...) java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

You are very likely missing the jTDS dependency. Do you have it declared in your pom.xml?

<dependency>
  <groupId>net.sourceforge.jtds</groupId>
  <artifactId>jtds</artifactId>
  <version>1.2.4</version>
</dependency>

Use any version that is appropriate for you (and maybe also tweak the scope).

To be more concise , in my jar are missing compiled files which should come from /test folder

This won't happen and is not supposed to happen, test sources and resources won't be packaged in the final jar by Maven, which is a good thing. If these files are supposed to be packaged in the final jar, move their sources to the source tree (not the test tree).


Could be some wrong dependencies added in my pom.xml ?

It could be. You should certainly have a JTDS dependency declared there, if you don't already.

As for the missing classes, are you expecting the net.sourceforge.jtds.jdbc.Driver to be in your JAR? If so, you're mistaken, this should be in the JTDS JAR which you obtain separately.

In any case, you can take the test step out of the equation. Start with a clean directory, and just run mvn compile. Then have a look at the target/classes directory to see which classes have been compiled there. If classes are missing at this step, then they're not being found by Maven. Are they in the src/main/java folder (or target/generated-sources for generated classes)? Does your pom override the default pattern matching for the compile phase?

You haven't really given much information, so I can't say more than to go through the process one step at a time, looking at the result each step of the way. Often one focuses on the wrong area initially, and a simple attention shift can be all that is needed to find a problem that is clear in retrospect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜