I have an Ant build.xml script that I'm trying to use. In it, I've added a taskdef to run some junit tests. However, I'm running into the dreaded classpath problems.
Because this is a weblogic application, Weblogic sets up ANT_HOME to the Weblogic ANT version, which is 1.6.5 In addition, we're trying to use JUnit 4, but the JUnit that comes with Weblogic is JUnit 3 based (I believe).
I thought it would be a simple thing to tell Ant to use the Ant and JUnit jars that I've checked in with my project rather than running with the Weblogic version, but I've been unable to make this work.
Here's what I have now:
<path id="junit.classpath">
<fileset dir="${applib.dir}">
<include name="junit-4.10.jar"/>
</fileset>
</path>
<taskdef name="myjunit"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
classpathref="junit.classpath">
<classpath>
<!-- These are here so that the junit task runs with these jars, which works -->
<pathelement location="${applib.dir}/junit-4.10.jar"/>
<pathelement location="${applib.dir}/ant-1.8.2/ant-junit4.jar"/>
</classpath>
</taskdef>
However, no matter what I do, Ant's classpath doesn't include JUnit/framework/Test:
BUILD FAILED
C:\build.xml:219: taskdef A class needed by class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask cannot be found: j
unit/framework/Test
I think the problem is that ANT_HOME is being set by Weblogic and thus ant-junit.jar is being added to the classpath when Ant starts up. ant -diagnostics confirms this.
The only way I've been able to solve this is to put junit-4.10.jar in the classpath directly, or put it in the BEA ANT_HOME library dir. However, that won't work in production environments.
So - how can I add junit-4.10.jar to the Ant classpath so the taskdef doesn't cause Ant to crash?
- The task is only used to run JUnit tests during code build, it isn't needed for deployment.
- Installing ANT and JUNIT on any and all machines that will use this script isn't really an option.
- Multiple platforms (unix and windows) need to be able to run the same build script, Windows for building code and Linux for deployment to Weblogic.
- I really don't want to have to deliver JUnit and ANT jars in production packages just to shut Ant up during the deployment phase when it isn't even going to run the task in question.
- I could have a separate build.xml file just to compile/run the junit test, but that will cause duplicate code and seems like a kludge.
Anyone have any suggestions on how to address this?