ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <>
Subject Re: junit task classpath issue, can't find jdbc drivers?
Date Mon, 10 Sep 2007 10:35:40 GMT
Preston, Brian wrote:
> Is there a common 'gotcha' with running the junit task and classpaths?
> Because I'm having a problem where my tests run against the database, so
> they need the drivers on the classpath, and they're not being found.
> Here's the error : 
> java.sql.SQLException: No suitable driver at
> java.sql.DriverManager.getConnection(Unknown Source) 
> When I run the Junit in Eclipse, it works fine. I have the db drivers on
> the classpath, but I must be missing something. 
> We have a utility project (DataConn) for handling db connections. It
> contains examples that require the db drivers. When I compile this
> project earlier in the build script, it compiles fine. I tried
> commenting out the classpath ref that has the drivers on it, just to
> test it, and it fails. 
> For the junit classpath, I have a refid that points to the classpath
> used by the DataConn project. But apparently something is wrong. 
> I'll try to include relevant snippets of the build file 
> <path id="DataConn.classpath">
>     <fileset dir="${DataConn.lib}">
>         <patternset refid="jar-files" />
>     </fileset>
> </path>
> DataConn.lib is where the driver jars are. Again, I tested that this is
> working because the compilation of the DataConn project works with this
> classpath, and fails when it's commented out. 
> <path id="test.classpath">
>     <fileset file="${junit.jar}"/>
>     <path refid="MainProj.classpath"/>
>     <pathelement location="${MainProj.bin}"/>
>     <pathelement location="${test.dir}"/>
>     <!-- need the db drivers -->
>     <path refid="DataConn.classpath"/>
> </path>
> <target name="test.compile" depends="MainProj.compile">
>         <javac srcdir="${test.src}" destdir="${test.dir}"
> classpathref="test.classpath" />
> </target>
> <target name="test" depends="test.compile">
>     <junit haltonfailure="true" printsummary="true">
>     	<classpath refid="test.classpath" />
>     	<test name="com.mycompany.project.TestSuiteFooImpl" />
>     	<formatter type="brief" usefile="false"/>
>     </junit>
> </target>
> FYI, the test.compile target step is successful as well. 
> In the test suite, there is a static initializer method which sets the
> 'jdbc.drivers' System property with a semicolon-delimited list of the
> drivers. Then it does other calls to our DataConn project to set up the
> connection pool. This all works fine when running this suite from within
> Eclipse. 

1. try setting junit to fork. so you know you are in a perfectly clean JVM
2. sometimes JDBC drivers like to be loaded (statically) before they 
support jdbc urls. Eclipse may have already done this, but your test 
code/app should do it too

Steve Loughran        
Author: Ant in Action 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message