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?
Related
This may look duplicate to something on SO however I have looked at this, this, this and this but have not found the solution that works.
The problem I have is I am getting this error on jenkins for non existing test suite. Below is the error printed in jenkins ant build log;
compile-tests-run:
[junit] Testsuite: com.smartstream.control.engine.validation.Batch-With-Multiple-Tests
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
[junit]
[junit] Testcase: null took 0 sec
[junit] Caused an ERROR
[junit] Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
[junit] junit.framework.AssertionFailedError: Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
[junit]
[junit] Running com.smartstream.control.engine.validation.Batch-With-Multiple-Tests
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
BUILD FAILED
u:\jenkins\workspace\control.unittests.execution.time.test\build\build.xml:256: The following error occurred while executing this line:
u:\jenkins\workspace\control.unittests.execution.time.test\engine\build\build.xml:287: Process fork failed.
Total time: 7 minutes 42 seconds
Build step 'Invoke Ant' marked build as failure
Archiving artifacts
Recording test results
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
Email was triggered for: Failure - Any
Sending email for trigger: Failure - Any
Sending email to: xxxxxxxx#abc.xom
Finished: FAILURE
now as you can see it seems to be failing on com.smartstream.control.engine.validation.Batch-With-Multiple-Tests however I don't have any such test suite in my entire workspace. I couldn't even find it as a literal string anywhere in the project.
The below search in the workspace returned nothing;
neither did the windows findstr;
I have tried increasing the ant build memory and permgen to no avail. The build is running with java 1.7.0_80-b15 and ant 1.9.6. Below is the junit ant task specification in engine/build.xml file;
<junit dir="." haltonfailure="false" printsummary="yes" forkmode="once" fork="yes" showoutput="yes" failureproperty="tests.failed">
<classpath location="${build.testclasses}" />
<classpath location="${resources.dir}" />
<classpath location="${common.properties}" />
<classpath location="${common.libs}" />
<formatter type="xml" />
<formatter type="plain" usefile="false" />
<jvmarg value="-Demma.coverage.out.file=${build.coveragereport}/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
<jvmarg value="-Xms512m" />
<jvmarg value="-Xmx1536m" />
<jvmarg value="-XX:MaxPermSize=512m" />
<jvmarg value="-XX:-UseSplitVerifier"/>
<batchtest todir="${build.report}">
<fileset dir="${test.dir}">
<include name="**/*Test.java" />
<exclude name="${excludeTestPattern1}" />
<exclude name="${excludeTestPattern2}" />
<exclude name="${excludeTestPattern3}" />
<exclude name="${excludeTestPattern4}" />
<exclude name="${excludeTestPattern5}" />
</fileset>
</batchtest>
</junit>
What I have tried so far
checked Delete workspace before build starts on jenkins job for a full clean build.
Initial xmx was 512m I updated it to be 1024m and then later 1536m
Initial perm size was 256m, have updated to 512m
have played around with fork and showoutput attributes in ant task
updated java and ant versions from initial try
Any help would be greatly appreciated.
I found a solution to this issue. I had to enable verbose logging for ant and through that the following stacktrace was observed;
Caused by: java.io.IOException: Cannot run program "u:\jenkins\tools\hudson.model.JDK\Java7\jre\bin\java.exe" (in directory "u:\jenkins\workspace\control.unittests.execution.time.test\engine"): CreateProcess error=206, The filename or extension is too long
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:428)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:442)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1257)
... 32 more
Caused by: java.io.IOException: CreateProcess error=206, The filename or extension is too long
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 37 more
Since jenkins creates workspace based on the build job name it was too long to create forked vm through it. I changed the jenkins job name and it resolved the issue.
I have some junit test cases where I create DatagramChannelFactory for every test case. When I run these test cases normally, I do not have any problem instantiating NioDatagramChannelFactory .
DatagramChannelFactory channelFactory = new NioDatagramChannelFactory(Executors.newFixedThreadPool(10));
But when I enable jacoco for the same piece of code, the instantiate fails. My jacoco is integrated with ant and the part of build.xml concerned looks like this :
Since jacoco requires fork="yes" attribute I'm adding the same.
<jacoco:coverage>
<junit printsummary="yes" haltonfailure="no" showoutput="yes" fork="yes" >
blah.. blah..
<batchtest fork="true" todir="${reportsUTrawdir}">
blah.. blah..
</batchtest>
</junit>
</jacoco:coverage>
and my junit target looks like below :
<junit printsummary="yes" haltonfailure="no" showoutput="yes">
<formatter type="xml" />
<batchtest fork="yes" todir="${reportsUTrawdir}">
blah.. blah..
</batchtest>
</junit>
The stack trace I get is :
Failed to create a selector.
org.jboss.netty.channel.ChannelException: Failed to create a selector.
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.openSelector(AbstractNioSelector.java:343)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.<init>(AbstractNioSelector.java:100)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.<init>(AbstractNioSelector.java:95)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.<init>(AbstractNioWorker.java:48)
at org.jboss.netty.channel.socket.nio.NioDatagramWorker.<init>(NioDatagramWorker.java:54)
at org.jboss.netty.channel.socket.nio.NioDatagramWorkerPool.createWorker(NioDatagramWorkerPool.java:35)
at org.jboss.netty.channel.socket.nio.NioDatagramWorkerPool.createWorker(NioDatagramWorkerPool.java:26)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.newWorker(AbstractNioWorkerPool.java:143)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.init(AbstractNioWorkerPool.java:81)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.<init>(AbstractNioWorkerPool.java:69)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.<init>(AbstractNioWorkerPool.java:55)
at org.jboss.netty.channel.socket.nio.NioDatagramWorkerPool.<init>(NioDatagramWorkerPool.java:29)
at org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory.<init>(NioDatagramChannelFactory.java:140)
at org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory.<init>(NioDatagramChannelFactory.java:124)
Is there anything I'm missing when I'm tearing down my test case. Please help me through.
EDIT : Added the cause I got from junit report :
Caused by: java.io.IOException: Unable to establish loopback connection
at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:106)
at java.security.AccessController.doPrivileged(Native Method)
at sun.nio.ch.PipeImpl.<init>(PipeImpl.java:122)
at sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:27)
at java.nio.channels.Pipe.open(Pipe.java:133)
at sun.nio.ch.WindowsSelectorImpl.<init>(WindowsSelectorImpl.java:105)
at sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:26)
at java.nio.channels.Selector.open(Selector.java:209)
at org.jboss.netty.channel.socket.nio.SelectorUtil.open(SelectorUtil.java:63)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.openSelector(AbstractNioSelector.java:341)
Caused by: java.net.SocketException: Permission denied: connect
at sun.nio.ch.Net.connect(Native Method)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:507)
at java.nio.channels.SocketChannel.open(SocketChannel.java:146)
at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:78)
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;.
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....
I have an intellij project where I am trying to create 2 jars. I have setup my buildfile and run build ALL artifacts. However, only my FIRST jar comes up. To try to get more information I ran the command line command: ant -buildfile buildfile.xml
In the result I get the following:
artifact.jar1:jar:
[mkdir] Created dir: ~/Projects/proj1/__artifacts_temp/jar1_jar
[jar] Building jar: ~/Projects/proj1/__artifacts_temp/jar1.jar
[copy] Copying 1 file to ~/Projects/proj1/__artifacts_temp/jar1_jar
artifact.jar2:jar:
[mkdir] Created dir: ~/Projects/proj1/__artifacts_temp/jar2_jar
[jar] Building jar: ~/Projects/proj1/__artifacts_temp/1/jar2.jar
[copy] Copying 1 file to ~/Projects/proj1/__artifacts_temp/jar2_jar
So it looks like both jars will be created. However... the next output is more discouraging.
build.all.artifacts:
[copy] Copying 1 file to ~/Projects/proj1
[delete] Deleting directory ~/Projects/proj1/__artifacts_temp
I have absolutely no idea why it would only copy 1 of the jars back. Any thoughts or ideas on how to get more information would be greatly appreciated.
Edit:
Here is what the build.all.artifacts section of my build script looks like
<target name="build.all.artifacts" depends="artifact.jar1:jar, artifact.jar2:jar" description="Build all artifacts">
<mkdir dir="${artifact.output.jar1:jar}"/>
<copy todir="${artifact.output.jar1:jar}">
<fileset dir="${artifact.temp.output.jar1:jar}"/>
</copy>
<mkdir dir="${artifact.output.jar2:jar}"/>
<copy todir="${artifact.output.jar2:jar}">
<fileset dir="${artifact.temp.output.jar2:jar}"/>
</copy>
<!-- Delete temporary files -->
<delete dir="${artifacts.temp.dir}"/>
</target>
Check buildfile.xml, there should be a <copy> task for the first jar and not for the second.
Update: Try using <fileset dir="${artifact.temp.output.jar2:jar}" erroronmissingdir="true"/> to see if there's something wrong with the path.
Also try to print the paths to check if they are correct:
<echo>${artifact.output.jar2:jar}</echo>
<echo>${artifact.temp.output.jar2:jar}</echo>