Build error: NoClassDefFoundError: org/apache/xpath/XPathAPI [duplicate] - java

This question already has answers here:
java.lang.NoClassDefFoundError: org/apache/xpath/XPathAPI
(2 answers)
Closed 3 years ago.
I have upgraded my J2EE web application from jdk6,tomcat6 to jdk7 and tomcat7
but while deploying teamcity is giving following error.
[xmltask] java.lang.NoClassDefFoundError: org/apache/xpath/XPathAPI
java.lang.NoClassDefFoundError: org/apache/xpath/XPathAPI
at com.oopsconsultancy.xmltask.jdk14.XPathAnalyser14.analyse(XPathAnalyser14.java:29)
at com.oopsconsultancy.xmltask.XmlReplace.apply(XmlReplace.java:72)
at com.oopsconsultancy.xmltask.XmlReplacement.apply(XmlReplacement.java:61)
at com.oopsconsultancy.xmltask.ant.XmlTask.processDoc(XmlTask.java:707)
at com.oopsconsultancy.xmltask.ant.XmlTask.execute(XmlTask.java:676)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:37)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: java.lang.ClassNotFoundException: org.apache.xpath.XPathAPI
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 25 more

The missing class is contained in xalan-2.7.0 (See Maven central). So I think the problem is how your classpath has been set.
Considering that this appears to be an error reported by the xmltask task, does this mean the error is being thrown by ANT?
Google found the following example which might be the answer to your problems:
https://wiki.nci.nih.gov/display/NBIA/Migration+to+Java+7
Add the xalan jar to the classpath of your taskdef:
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath>
<pathelement path="${common.lib.dir}/xmltask-1.15.1.jar" />
<pathelement path="${common.lib.dir}/xalan-2.7.1.jar"/>
</classpath>
</taskdef>

if using maven add this to your dependencies section:
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.0</version>
</dependency>

I am not sure but, i guess jar named xalan-2.4.0.jar is missing
please download it and place inside.
http://www.java2s.com/Code/Jar/x/Downloadxalan240jar.htm

Add xpath to your classpath and try the deploy again. If you are not sure which xpath jar you need search in the tomcat libraries folder for xpathapi jar
Xpathapi is a jar used for evaluating xpaths (related to xml) in java. if you are not sure which version you need, google for it and fetch the latest xpath api jar .

For now I just remove
from my build.xml, and its working.
I know its not a solution but we have to deliver.

In Build.xml, change the java version to 1.7 and classpath XMLTask from 1.15.1 to 1.16.1.. It works

This is how I solved this, inlcuding Xalan and Serializer
Download xalan-j2-2.7.0.jar & serializer-2.7.0.jar
Update build.xml to include these jars in path
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath>
<pathelement location="../xmltask-v1.14.jar"/>
<pathelement path="../xalan-j2-2.7.0.jar"/>
<pathelement path="../serializer-2.7.0.jar"/>
</classpath>
</taskdef>
This should get it running.

You should remove import org.apache.xpath.operations.String;.

Related

JAXWS-RI WSGEN configure to use specific JDK

I am currently trying to compile an application in CruiseControl using ANT but get an UnsupportedClassVersionError. The setup is as follows:
Environment: Windows server 2012
IDE: Eclipse Luna running JDK 8
Build server: CruiseControl 2.4.1 running on JDK 6
Build tool: ANT
Compiler: JDK 8 update 102
JAXWS-RI: 2.2.10
CruiseControl is installed as a service and during startup JAVA_HOME is set to JDK 6 in a file called wrapper.conf. As target version is Java 8 another env variable is also set.
set.JAVA_HOME=C:/jdk1.6
set.JAVA_HOME_JDK8=C:/jdk1.8.0_102
In the ANT build scripts the javac task has fork set to true and specifies the path to the java executable like this:
<property name="javac.fork" value="yes"/>
<property environment="env"/>
<property name="javac.location" value="${env.JAVA_HOME_JDK8}\\bin\\javac.exe"/>
<javac includeantruntime="false" destdir="${builddir}" debug="true"
target="1.8" source="1.8" debuglevel="lines,vars,source"
fork="${javac.fork}" executable="${javac.location}">
The above setup works well but fails when I try to use JAXWS-RI to create artifacts. The specific error reported is:
java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:539)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:384)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: C:\path\build.xml:133: The following error occurred while executing this line:
java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:539)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:384)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:37)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)
... 12 more
Caused by: java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1225)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:37)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)
... 20 more
Caused by: java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at com.sun.tools.ws.wscompile.WsgenOptions.getClass(WsgenOptions.java:305)
at com.sun.tools.ws.wscompile.WsgenOptions.validateEndpointClass(WsgenOptions.java:244)
at com.sun.tools.ws.wscompile.WsgenOptions.validate(WsgenOptions.java:235)
at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:131)
at com.sun.tools.ws.ant.WsGen2.runInVm(WsGen2.java:357)
at com.sun.tools.ws.ant.WsTask2.execute(WsTask2.java:423)
at com.sun.tools.ws.ant.WsGen2.execute(WsGen2.java:351)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
... 23 more
As far as I can see it is thrown because WSGEN uses JAVA_HOME (pointing to JDK 6) to find the Java executable subsequently used to generate stuff.
WSSGEN setup is:
<target name="wsgen-compile">
<mkdir dir="${builddir}"/>
<javac includeantruntime="false" destdir="${builddir}" debug="true" target="1.8" source="1.8" debuglevel="lines,vars,source" fork="${javac.fork}" executable="${javac.location}">
<src path="${src.tmp}" />
<classpath>
<pathelement path="${classpath}"/>
<pathelement path="${builddir}/../../common/bin"/>
<pathelement path="${builddir}/../../server/bin"/>
<fileset dir="${libdir}">
<include name="*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="wsgen-generate">
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen2">
<classpath>
<fileset dir="${webserviceslibdir}/jax/jaxws-ri/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<wsgen verbose="true"
genwsdl="true"
xendorsed="false"
keep="true"
resourcedestdir="properties"
destdir="${src.tmp}"
sei="com.nordea.nordiccms.server.webservices.${service}">
<classpath>
<pathelement path="${classpath}"/>
<pathelement path="${builddir}/../../common/bin"/>
<pathelement path="${builddir}/../../server/bin"/>
<fileset dir="${libdir}">
<include name="*.jar"/>
</fileset>
</classpath>
<arg value="J.java_home"/>
</wsgen>
<delete>
<fileset dir="${src.tmp}">
<include name="**/*.class"/>
</fileset>
</delete>
</target>
<target name="wsgen" depends="compile">
<echo message=""/>
<echo message="Building ${distributionnameserver} WebService files"/>
<echo message="----------"/>
<mkdir dir="${builddir}/wsgen"/>
<delete dir="${src.tmp}"/>
<mkdir dir="${src.tmp}"/>
<ant target="wsgen-generate">
<property name="service" value="Service1"/>
</ant>
<ant target="wsgen-compile"/>
<delete dir="${src.tmp}"/>
</target>
I want to configure WSGEN to use JDK 8 instead of JDK 6 while compiling, but I have so far been unable to do so. Does anybody know how I might solve this problem? I should mention that upgrading CruiseControl to run on JDK8 is not an option at this point.
The error has the following...
Caused by: java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0
/*snip*/
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at com.sun.tools.ws.wscompile.WsgenOptions.getClass(WsgenOptions.java:305)
The error is saying that the version of the Java Runtime (the JRE) running Ant is older than JRE version 52.0. JRE 52.0 is the major number for Java SE 8 (see How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version).
The JRE running Ant is trying to interact with the Java class com/company/area/thing/services/Service1. However, the Service1 class was compiled with Java 8. The older JRE running Ant doesn't know how to handle Java 8 classes, so the build fails.
Try running Ant with Java 8. Set JAVA_HOME to point to an installation of JDK 8.
Use the following build.xml script to verify the version of Java being used:
<project name="ant-jdk-version">
<echo>Java Version via Ant: ${ant.java.version}</echo>
<echo>Java Version System Prop: ${java.version}</echo>
</project>
The script should output something similar to...
[echo] Java Version via Ant: 1.8
[echo] Java Version System Prop: 1.8.0_60

Jar files inside another jar error NoClassDefFoundError and ClassNotFoundException

I have created jar file which contains dependent jar but when I try to run the class file inside that it gives error as
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.TestFlowProcessor.<clinit>(WebMethodsFlowProcessor.java:37)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
My Manifest file :
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: test
Build-Jdk: 1.8.0_45
Class-Path: log4j-1.2.17.jar slf4j-api-1.7.10.jar commons-logging-1.1.jar dom4j-1.6.1.jar jsoup-1.8.3.jar junit-3.8.1.jar log4j-1.2.17.jar poi-3.8-20120326.jar poi-ooxml-3.8-20120326.jar poi-ooxml-schemas-3.8-20120326.jar SAPIntegrationDirectory.jar stax-api-1.0.1.jar xmlbeans-2.3.0.jar
Main-Class: com.TestFlowProcessor
I am trying to execute using
java -cp WMTOFuse.jar com.TestFlowProcessor
You could use 'Ant' 'jar' task for this. Refer https://ant.apache.org/manual/Tasks/jar.html
<jar destfile="build/main/checksites.jar">
<fileset dir="build/main/classes"/>
<restrict>
<name name="**/*.class"/>
<archives>
<zips>
<fileset dir="lib/main" includes="**/*.jar"/>
</zips>
</archives>
</restrict>
<manifest>
<attribute name="Main-Class"
value="com.acme.checksites.Main"/>
</manifest>
</jar>
above creates a single jar file containing inside it contents of multiple jars.
The problem is seems to be with log4j-1.2.17.jar. I have changed it to
log4j-1.2.15.jar & above mentioned issue is resolved. Thanks everyone
for helping me out with this.

Using external libraries in Java

Here's the error I keep getting at runtime:
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
Note, this is a runtime error, not a compile-time one. Both tasks in my build.xml have an identical classpath set, and the compile task runs fine every single time:
<path id="classpath">
<fileset dir="lib" includes="*.jar" />
</path>
<target name="compile">
<mkdir dir="build/classes"/>
<javac
srcdir="src"
classpathref="classpath"
includeantruntime="false"
destdir="build/classes"
/>
</target>
...
<target name="run" depends="clean,compile,jar">
<java
jar="build/jar/${project.name}.jar"
fork="true"
classpathref="classpath"
>
<sysproperty key="java.library.path" path="${path.lib}/windows"/>
</java>
</target>
Trying to run the jar via command-line manually yields the same result:
java -cp .:lib/*.jar -Djava.library.path=lib/windows -jar build/jar/JUtopia.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
Note that the library jarfile is ok:
bash-3.1$ jar -tf lib/lwjgl.jar | grep LWJGLException
org/lwjgl/LWJGLException.class
And the native libraries are in place:
bash-3.1$ ls lib/windows/lwjgl.dll
lib/windows/lwjgl.dll
The question: where the blazes have I gone wrong? I've been beating at this problem for nearly 3 days. Any help would be much appreciated.
Full result stack:
clean:
[delete] Deleting directory C:\Users\mkumpan\Projects\JUtopia\build
compile:
[mkdir] Created dir: C:\Users\mkumpan\Projects\JUtopia\build\classes
[javac] Compiling 12 source files to C:\Users\mkumpan\Projects\JUtopia\build\classes
jar:
[mkdir] Created dir: C:\Users\mkumpan\Projects\JUtopia\build\jar
[jar] Building jar: C:\Users\mkumpan\Projects\JUtopia\build\jar\JUtopia.jar
run:
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
[java] at JUtopia.<init>(Unknown Source)
[java] at JUtopia.main(Unknown Source)
[java] Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] ... 2 more
P.S.: Note, I'm using Console2 with bash in a windows environment for my commandline work, thus the windows natives yet linux shell syntax. Using vanilla cmd to run the jar yields the same result.
-jar...
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored. - reference
try setting the Class-Path in the JAR
Alternatively try running without the -Jar option, by specifying the main class on the command line
One of the possible causes is that while loading the class LWJGLException it also references another class which can't be found on the classpath. Hence the reported error is sometimes not clear.
Important here is thet you have this NoClassDefFoundError and not ClassNotFoundException which is the error you assume you are having: it cannot find the class LWHLException, yes it can ! But it cannot load it....

JDO3.0 enhance failure in GAE 1.7.2

I use ant to build my GAE WebApp. This is the datanucleus target:
<target name="datanucleusenhance" depends="compile"
description="Performs enhancement on compiled data classes.">
<enhance_war war="war">
</enhance_war>
</target>
This is the error I got:
org.datanucleus.exceptions.NucleusException: Plugin (Bundle) "org.datanucleus" is already registered. Ensure you dont have multiple JAR versions of the same plugin in the classpath. The URL
"file:/home/xxxx/.eclipse/org.eclipse.platform_4.2.0_1473617060/plugins/com.google.appengine.eclipse.sdkbundle_1.7.2/appengine-java-sdk-1.7.2/lib/opt/tools/datanucleus/v1/datanucleus-core-1.1.5.jar" is already registered, and you are trying to register an identical plugin located at URL "file:/war/WEB-INF/lib/datanucleus-core-3.1.0-m5.jar."
I've tried this ant target:
<target name="datanucleusenhance" depends="compile" description="Performs enhancement on compiled data classes.">
<enhance_war war="war">
<args>
<arg value="-enhancerVersion" />
<arg value="v3.1.0" />
</args>
</enhance_war>
</target>
I've tried to delete "datanucleus-core-1.1.5.jar". The error then is:
java.lang.RuntimeException: Unexpected exception
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:76)
at com.google.appengine.tools.enhancer.Enhance.<init>(Enhance.java:71)
at com.google.appengine.tools.enhancer.Enhance.main(Enhance.java:51)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:74)
... 2 more
Caused by: java.lang.NoClassDefFoundError: org/datanucleus/OMFContext
at org.datanucleus.enhancer.DataNucleusEnhancer.<init>(DataNucleusEnhancer.java:172)
at org.datanucleus.enhancer.DataNucleusEnhancer.<init>(DataNucleusEnhancer.java:150)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1157)
... 7 more
Caused by: java.lang.ClassNotFoundException: org.datanucleus.OMFContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at com.google.appengine.tools.enhancer.EnhancerLoader.loadClass(EnhancerLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 10 more
How can I use JDO3.0 with GAE1.7.2?
Using the GAE plugin for Intellij, I had to remove the default configured orm directory, and specifically add the higher version libraries.
The GAE SDK is organized as such:
/lib/user/orm (default persistence libraries I removed)
AND
/lib/opt/user/datanucleus/v2
To access this configuration in IntelliJ, from the context menu for my project:
{context menu} -> Open Module Settings -> Libraries -> AppEngine ORM
Use the [-] button to remove the jars within this directory: /lib/user/orm
Use the [+] button to add the jars within this directory: /lib/opt/user/datanucleus/v2
Got the answer. The correct ant target should be:
<target name="datanucleusenhance" depends="compile" description="Performs enhancement on compiled data classes.">
<enhance_war war="war">
<args>
<arg value="-enhancerVersion" />
<arg value="v2" />
</args>
</enhance_war>
</target>
the version is the GAE JDO/JPA plugin version.(Thanks DataNucleus!:)
You seem to be confusing which versions of dependent jars to use. GAE 1.7.2 uses GAE JDO/JPA plugin v2.x, which in turn needs DataNucleus 3.x. You evidently have (various) DataNucleus 1.x jars present.

Trouble running JUnit from Ant

Here's the target I'm using to run my tests:
<target name="run-tests" description="run the tests" depends="compilation">
<junit>
<sysproperty key="tests.basedir" value="${SPECIAL_PATH}/unit_tests"/>
<classpath>
<pathelement location="${COMPILED_CLASSES}"/>
<pathelement location="${basedir}/junit-4.8.1.jar"/>
</classpath>
<batchtest>
<fileset dir="${COMPILED_CLASSES}/unit_tests/">
<include name="**/Test*.class"/>
<exclude name="**/*$*"/>
</fileset>
</batchtest>
</junit>
</target>
However, every time I try to run this target, all my tests fail with something like:
[junit] java.lang.ClassNotFoundException: testpackage.TestMyClass
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
[junit] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:247)
The SPECIAL_PATH property points to the source code of the classes. The COMPILED_CLASSES property points to the place the .class files have been put. And I need the tests.basedir property because I use it from my unit tests.
What am I doing wrong?
EDIT:I also thought I should explain the exclude of the $. I'm excluding anonymous classes, because they don't represent TestCases, they're only used from them.
You are telling Junit to execute each test class in ${COMPILED_CLASSES}/unit_tests/ but you are putting just ${COMPILED_CLASSES} on the classpath. You probably need to change your classpath entry to
<pathelement location="${COMPILED_CLASSES}/unit_tests/"/>
Since your claspath has
${COMPILED_CLASSES}
and your test classes are in
${COMPILED_CLASSES}/unit_tests
they would need to be in package
unit_tests.<whatever the classpath is>
traditionally this is why people compile normal sources to target/classes and test sources to target/test-classes
You might need to compile the UnitTests. Could you post where you use the javac task?

Categories