ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Preston, Brian" <>
Subject RE: junit task classpath issue, can't find jdbc drivers?
Date Mon, 10 Sep 2007 19:33:48 GMT
Thanks for your reply. The fork worked. I should've also mentioned that
the problem was happening when running from the command line as well,
i.e. outside of Eclipse. After I posted this I continued reading the
online junit chapter from your book and read about the fork there. I
just hadn't tried it yet, I was a little wary of fork for some unfounded
fear of runaway processes or something. But it worked, so it's all good.


-----Original Message-----
From: Steve Loughran [] 
Sent: Monday, September 10, 2007 6:36 AM
To: Ant Users List
Subject: Re: junit task classpath issue, can't find jdbc drivers?

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
> 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  
This e-mail message is intended only for the personal use of the 
recipient(s) named above. If you are not an intended recipient,  
you may not review, copy or distribute this message. If you have  
received this communication in error, please notify First DataBank 
Support ( immediately by e-mail  
and delete the original message. 

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

View raw message