views:

33

answers:

2

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?

A: 

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.

Andrzej Doyle
Thank you very much for your post , my source files are in /src , not in src/main/java , i changed the default build source directory to "sourceDirectory>${basedir}/src</sourceDirectory>" in build tags.
Eeesh - well, if you stray away from the defaults, you better hope you reconfigured everything right else you're on your own! ;-)
Andrzej Doyle
also those test are in /test directory to run them i added <testSourceDirectory>${basedir}/test</testSourceDirectory> in build tags
:) , it was necessary to do that, i must migrate a project from ant build to maven build...
A: 

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).

Pascal Thivent
That dependency will likely need <scope>runtime</scope> added to it. Just to be _absolutely_ clear. :)
Dominic Mitchell
@Dominic: Yes, probably (or maybe `provided`). But I have no idea what the OP is doing exactly.
Pascal Thivent
Thanks for helping !