I am using ant 1.9.0 to run my Java project.i have a bat file which has command ant clean compile run.the clean and compile is working but for the target run I am getting below error
C:\Users\Susanta\MyMaven\MyMavenProject\build] on class org.apache.
tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: java.lang.NoClassDefFoundErrorjunit/framework/TestListener
I am attaching the build.xml please let me know the issue in my build.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>
<project name="MyMavenProject" default="usage" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="${user.home}/.m2/repository/"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="test.reportsDir" value="${test.dest}/test_reports"/>
<path id="testcase.path">
<pathelement location="${test.dest}"/>
<fileset dir="${ws.jars}">
<include name="*.jar"/>
</fileset>
</path>
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="**/*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath------: ${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.5"
classpath="${test.classpath}"
>
</javac>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.run">
<fileset dir="${ws.jars}" includes="**/*.jar"/>
</path>
<target name="run" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.reportsDir}" includes="**/*"/>
</delete>
<java jar="${ws.jars}" fork="true" spawn="true" />
<junit fork="yes" haltonfailure="no" printsummary="yes">
<classpath refid="test.run" />
<!-- <classpath ="${test.classpath}"/> -->
<batchtest todir="${test.reportsDir}" fork="true">
<fileset dir="${test.dest}">
<!--include name="tests/LoginTest.class" />
<include name="tests/Parameterized_Test.class" />
<include name="tests/TestApplication.class" /-->
<include name="com/testing/GoogleTest.class" />
<include name="com/testing/YahooTest.class" />
</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="testcase.path" />
</junit>
<junitreport todir="${test.reportsDir}">
<fileset dir="${test.reportsDir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.reportsDir}" />
</junitreport>
</target>
below is the error:
C:\Users\Susanta\MyMaven\MyMavenProject\build] on class org.apache.
tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: java.lang.NoClassDefF
oundError: junit/framework/TestListener
[exec] at java.lang.ClassLoader.defineClass1(Native Method)
[exec] at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
[exec] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[exec] at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[exec] at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1385)
[exec] at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoaderjava:1064)
[exec] at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:58)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] at java.lang.ClassLoader.defineClass1(Native Method)
[exec] at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
[exec] at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1128)
[exec] at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1299)
[exec] at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1354)
[exec] at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoaderjava:1315)
[exec] at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:52)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] at java.lang.Class.forName0(Native Method)
[exec] at java.lang.Class.forName(Class.java:266)
[exec] at
org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:286)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmExit(JUnitTask.java:1653)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmCrash(JUnitTask.java:1617)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1099)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:851)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1899)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:800)
[exec] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[exec] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[exec] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[exec] at java.lang.reflect.Method.invoke(Method.java:601)
[exec] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[exec] at org.apache.tools.ant.Task.perform(Task.java:348)
[exec] at org.apache.tools.ant.Target.execute(Target.java:435)
[exec] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[exec] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
[exec] at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
[exec] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[exec] at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
[exec] at org.apache.tools.ant.Main.runBuild(Main.java:851)
[exec] at org.apache.tools.ant.Main.startAnt(Main.java:235)
[exec] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
[exec] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
[exec] Caused by: java.lang.ClassNotFoundException: junit.framework.TestListener
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] ... 48 more
[exec]
[exec] Total time: 7 seconds
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.773s
[INFO] Finished at: Mon Jul 07 03:01:39 IST 2014
[INFO] Final Memory: 7M/18M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:
run (default) on project MyMavenProject: An Ant BuildException has occured: exec
returned: 1
[ERROR] around Ant part ...<exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" e
xecutable="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="
true">... # 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build
-runtheapp.xml
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project MyMaven
Project: An Ant BuildException has occured: exec returned: 1
around Ant part ...<exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" executabl
e="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="true">..
. # 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build-runthea
pp.xml
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: An Ant BuildException
has occured: exec returned: 1
around Ant part ...<exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" executable="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="true">..
. # 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build-runtheapp.xml
this appears to be a known bug in ANT 1.9.0. see here: Bamboo Ant Task fails when running junit task
read comments #4, #5, #8 & #20 # THIS Link for some help.
The ANT manual describes how the junit task requires an extra jar. This can be downloaded from Maven Central
List of junit versions
And installed in the following directory:
$HOME/.ant/lib
Personally I use an ANT plugin called ivy to manage my build's dependencies, see:
Class not found with Ant, Ivy and JUnit - error in build.xml?
Use Ant in netbeans to dynamically fetch latest versions of external libraries during build
Take a look at your error message:
C:\Users\Susanta\MyMaven\MyMavenProject\build] on class \
org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: \
java.lang.NoClassDefFoundError junit/framework/TestListener
Note the NoClassDefFoundError which means Ant couldn't find the class being referenced by one of your tasks. Was there a line number associated with this error? There should have been one pointing to the line that contains your <junit/> task. Even without that, you see that the class not found is junit/framework/TestListener.
The error messages in Java applications can be a bit intimidating because you see dozens, maybe hundreds of lines of stack trace. However, think of a Java program crash as a car accident. A car might have gone careening off the road, hit a telephone pole, bounced off that, hit another car, bounced off that, knocked over a fire hydrant, etc. You see a long trail of damage, but if you look at the first place where the accident occurred, you can usually see the problem (Look, there's a banana peel on the road!)
The same is true in Java error messages. The first line will usually tell you exactly what you need to know, and the exceptions are pretty easy to read. In this case, NoClassDefFoundError and it points to junit as the culprit. The next time you see something like this, you'll know what to look for.
As pointed out by Mark O'Connor, the jars needed for the JUnit task is not included with Ant. In fact, a lot of the defined tasks don't have the required jars to run those tasks, as you can see in this table (and <junit> is the fourth item in that table).
In the Ant manual on JUunit task, it states you can do the following:
Note: You must have junit.jar available. You can do one of:
Put both junit.jar and ant-junit.jar in ANT_HOME/lib.
Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable.
Add both JARs to your classpath using -lib.
Specify the locations of both JARs using a <classpath> element in a <taskdef> in the build file.
Leave ant-junit.jar in its default location in ANT_HOME/lib but include junit.jar in the passed to . (since Ant 1.7)
I personally prefer that last one. I usually place junit.jar in ${basedir}/antlib/junit. This way, when someone checks out my project, they get junit with it.
In the Ant FAQ it discusses some issues with <junit>.
Related
I am building this project https://github.com/oracle/visualvm . I have JDK10 in my system. I changed the source and target option in build xml to 1.8 from 1.5, as there were error saying 1.5 is not supported anymore. Now, I am getting a compile error pointing to common.xml which is in some other sub-folder.
I have no idea, what is wrong as the error log is also very vague. Also, I am working with Ant for the first time.
Here is the log.
C:\dev\jvisualvm\visualvm\visualvm\netbeans\harness\suite.xml:163: The following error occurred while executing this line:
C:\dev\jvisualvm\visualvm\visualvm\netbeans\harness\common.xml:200: Compile failed; see the compiler error output for details.
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1425)
at org.netbeans.nbbuild.CustomJavac.compile(CustomJavac.java:102)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1133)
at org.netbeans.nbbuild.CustomJavac.execute(CustomJavac.java:83)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:306)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:225)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:834)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
The part of common.xml where the error is thrown looks like this. (nb-javac srcdir tag)
<target name="compile" depends="init,up-to-date" unless="is.jar.uptodate">
<mkdir dir="${build.classes.dir}"/>
<depend srcdir="${src.dir}" destdir="${build.classes.dir}" cache="${build.dir}/depcache">
<classpath refid="cp"/>
</depend>
<property name="javac.fork" value="false"/>
<nb-javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${build.compiler.debug}" debuglevel="${build.compiler.debuglevel}" encoding="UTF-8"
deprecation="${build.compiler.deprecation}" optimize="${build.compiler.optimize}" source="1.8" target="1.8" includeantruntime="false"
fork="false">
<classpath refid="cp"/>
<compilerarg line="${javac.compilerargs}"/>
<processorpath refid="processor.cp"/>
</nb-javac>
<copy todir="${build.classes.dir}">
<fileset dir="${src.dir}" excludes="${jar-excludes}"/>
</copy>
<processjsannotation classes="${build.classes.dir}" asm="${asm.jar}">
<classpath refid="cp"/>
</processjsannotation>
</target>
Can anyone point me to some direction to resolve this?
You need to build VisualVM with JDK 8. https://github.com/oracle/visualvm clearly mentions it in Get the tools section.
I am using Ant to run my Java application. I have my main in Subscriber class which uses other libraries. So I wanted to run the Controller.Subscriber. But I get the following bug:
[java] Error: A JNI error has occurred, please check your installation and try again
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/paho/client/mqttv3/MqttCallback
[java] at java.lang.Class.getDeclaredMethods0(Native Method)
[java] at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
[java] at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
[java] at java.lang.Class.getMethod0(Class.java:3018)
[java] at java.lang.Class.getMethod(Class.java:1784)
[java] at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
[java] at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
[java] Caused by: java.lang.ClassNotFoundException: org.eclipse.paho.client.mqttv3.MqttCallback
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] ... 7 more
[java] Java Result: 1
My Ant file is the following:
<project default="run">
<target name="run">
<java classname="Controller.Subscriber" fork="true">
<classpath>
<pathelement path="target/classes"/>
</classpath>
</java>
</target>
</project>
The path to the Subscriber class: target/classes/Controller/Subscriber.class
What am I doing wrong? Do I have to first to create jar file from my class files to can run the java program or can I execute the class files? Or do I miss a parameter in my java command?
I also tried the following Ant file by giving explicit classpath:
<project default="run">
<target name="run">
<java classname="Controller.Subscriber" fork="true" classpath="classpath">
<classpath>
<pathelement path="target/classes"/>
</classpath>
</java>
</target>
<path id="classpath">
<fileset dir="target">
<include name="*.jar"/>
</fileset>
</target>
</project>
But I am getting the same error message.
I have found the solution to the problem: I have to use classpathref instead of classpath. For some reason classpath="classpath" does not read the id "classpath". But classpathref solved the problem.
I'm trying to follow the instructions provided by Oracle for packaging a Java App for distribution on a Mac.
http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
I'm using a Mac running OS 10.11.6. Everything works fine until I get to the code signing step. After scouring the net I have created the following ant script snippet.
<property name="MyApp.app" location="dist/ButtonDemo.app"/>
<property name="jdk" value="jdk1.8.0_101.jdk"/>
<exec executable="chmod">
<arg line="-R a+w ${MyApp.app}"/>
</exec>
<apply executable="codesign">
<arg line="-f -s 'Developer ID Application: MyName'"/>
<fileset dir="${MyApp.app}/Contents/PlugIns/${jdk}" />
</apply>
<exec executable="codesign">
<arg line="-f -s 'Developer ID Application: MyName' ${MyApp.app}"/>
</exec>
<!-- verify codesign -->
<exec executable="codesign" failonerror="true">
<arg line="-d --verbose=4 --strict ${MyApp.app}"/>
</exec>
<!-- verify gatekeeper -->
<exec executable="spctl" failonerror="true">
<arg line="--assess --verbose=4 --type execute ${MyApp.app}"/>
</exec>
I get the following output.
clean:
[delete] Deleting directory /Users/mike/ButtonDemo/components-ButtonDemoProject/dist/ButtonDemo.app
bundle-buttonDemo:
[bundleapp] Creating app bundle: ButtonDemo
sign:
[exec] Executable=/Users/mike/ButtonDemo/components-ButtonDemoProject/dist/ButtonDemo.app/Contents/MacOS/JavaAppLauncher
[exec] Identifier=components.ButtonDemo
[exec] Format=app bundle with Mach-O thin (x86_64)
[exec] CodeDirectory v=20200 size=341 flags=0x0(none) hashes=5+3 location=embedded
[exec] Hash type=sha256 size=32
[exec] CandidateCDHash sha1=8e4ec99904729d3faf45b8d5f26048d16a9f11c5
[exec] CandidateCDHash sha256=1feeb3eb8479ddfdf25e09cc5660e992f52bda06
[exec] Hash choices=sha1,sha256
[exec] CDHash=1feeb3eb8479ddfdf25e09cc5660e992f52bda06
[exec] Signature size=8919
[exec] Authority=Developer ID Application: MyName (XXXX)
[exec] Authority=Developer ID Certification Authority
[exec] Authority=Apple Root CA
[exec] Timestamp=Sep 13, 2016, 2:47:41 AM
[exec] Info.plist entries=16
[exec] TeamIdentifier=XXXX
[exec] Sealed Resources version=2 rules=12 files=4
[exec] Internal requirements count=1 size=184
[exec] /Users/mike/ButtonDemo/components-ButtonDemoProject/dist/ButtonDemo.app: code has no resources but signature indicates they must be present
BUILD FAILED
/Users/mike/ButtonDemo/components-ButtonDemoProject/build.xml:46: exec returned: 1
A simple check of the application bundle at dist/ButtonDemo.app/Contents/Resources shows that there are resources. Why do I get this error?
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 am trying to build using an Ant task that uses exec. Here is a snippet of my task:
<exec executable="cmd" failonerror="true" osfamily="windows">
<arg value="/c" />
<arg value="${path.installer}" />
<arg value="-silent"/>
<arg value="-allowDownload"/>
<arg value="-eulaAccepted"/>
</exec>
This is essentially an installer. When I am trying to run the installer (.exe) from the path, I am getting the following error:
C:\Users\abc\jenkins\install.xml:57: exec returned: 7 (line 57 points to beginning of exec)
I ran ant with verbose option to get more details:
[antcall] Exiting C:\Users\abc\jenkins\install.xml.
[echo] Installing new build from C:\Users\abc\jenkins\BA\integration_win\Nuze.exe
[exec] Current OS is Windows 7
[exec] Executing 'cmd' with arguments:
[exec] '/c'
[exec] 'C:\Users\abc\jenkins\BA\integration_win\Nuze.exe
[exec] '-silent'
[exec] '-allowDownload'
[exec] '-eulaAccepted'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
target 'install.nuze' failed with message 'exec returned: 7'.
BUILD FAILED
C:\Users\abc\jenkins\install.xml57: exec returned: 7
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:646)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:672)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:498)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExeutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Also I can confirm that my Jenkins slave has access to C:\Users\abc\jenkins\BA\integration_win\Nuze.exe
and I can install manually from that location without any issues. Any idea on where I am erring? I looked up error codes, but generally the tip I got is that there could be some issue with ant configuration. Any pointers? Thanks a ton in advance for the help.
Doesn't look like a ANT issue. "7" is the return code of the program you're running. You need to consult the documentation of the "nuze" program you are running.
Non-zero error codes indicate to ANT that the program has failed and programmers often return different codes to indicate to the calling program what went wrong. Standard OS stuff.
I am not very knowledgeable on this subject but sense there are no other answers I figured I would give it a shot. From looking at similar problems maybe try re-phrasing your xml
<exec executable="cmd" failonerror="true" osfamily="windows">
<arg line="/c ${path.installer} -silent -allowDownload -eulaAccepted"/>
</exec>