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....
Related
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 working on an ANT script now for a web application(And I have very minimal knowledge in ant script and weblogic server administration).
When I execute the ant script , everything work fine except the script fail to precompile the jsps. PFB the ant script for jsp precompile
<!-- run jsp compile -->
<target name="jspc" unless="warBuild.notRequired" depends="compileAll">
<java classname="weblogic.jspc" fork="yes" failonerror="true">
<arg line="-compiler ${WL_COMPILER} -nowarn -compileAll -webapp ${build} -depend -d ${classes}"/>
<classpath>
<pathelement path="${app.classpath};${classes}"/>
</classpath>
</java>
</target>
And PFB the error log
jspc:
[java] java.lang.NullPointerException
[java] at weblogic.jsp.internal.java.JavaCompilationContext$JavacJavaCompilationContext.init(JavaCompilationContext.java:67)
[java] at weblogic.jsp.internal.CPL.createJavaCompilationContext(CPL.java:584)
[java] at weblogic.jsp.internal.CPL.setClassLoader(CPL.java:555)
[java] at weblogic.servlet.jsp.JspCLLManager.initCompilerOptions(JspCLLManager.java:396)
[java] at weblogic.servlet.jsp.JspCLLManager.initialize(JspCLLManager.java:235)
[java] at weblogic.servlet.jsp.JspCLLManager.(JspCLLManager.java:228)
[java] at weblogic.servlet.jsp.JspCLLManager.(JspCLLManager.java:221)
[java] at weblogic.servlet.jsp.JspCLLManager.compileJsps(JspCLLManager.java:126)
[java] at weblogic.servlet.jsp.jspc20.runBodyInternal(jspc20.java:456)
[java] at weblogic.servlet.jsp.jspc20.runBody(jspc20.java:265)
[java] at weblogic.utils.compiler.Tool.run(Tool.java:158)
[java] at weblogic.utils.compiler.Tool.run(Tool.java:115)
[java] at weblogic.jspc.main(jspc.java:22)
[java] Unexpected exception while compiling jsps :java.lang.NullPointerException
Any help will be appreciated .Thanks in advance
Got the solution .
The issue is because the jre version of weblogic and jre version used in the workspace(Eclipse) was different.As a result the compilation of jsps were failed.I have changed the recommended jre version, ie jre1.6 (for weblogic 10.3.5) and it worked fine.
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;.
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.
I'm developing an Ant script for my project purposes and figured out that my proxy causes problem for me. Here is the simplest example from Apache documentation of 'copy' task:
=================== build.xml =====================
<project default="simplestCopy">
<property name="test.dir" value="${basedir}/test/" />
<target name="simplestCopy">
<mkdir dir="${test.dir}" />
<copy todir="${test.dir}" flatten="true">
<resources>
<url url="http://ant.apache.org/index.html"/>
</resources>
</copy>
</target>
</project>
I've got next error:
d:\temp>ant
Buildfile: d:\temp\build.xml
simplestCopy:
java.net.ConnectException: Connection refused: connect
BUILD FAILED
d:\temp\build.xml:7: Warning: Could not find resource url "http://ant.apache.org/index.html" to copy.
I've tried to set kind of
<property name="java.net.useSystemProxies" value="true" />
And define this property in command line
d:\temp>ant -Djava.net.useSystemProxies=true -verbose
But got same error:
d:\temp>ant -Djava.net.useSystemProxies=true -verbose
Apache Ant version 1.8.1 compiled on April 30 2010
Trying the default build file: build.xml
Buildfile: d:\temp\build.xml
Detected Java version: 1.6 in: c:\ProgramFiles\Java\jdk1.6.0_24\jre
Detected OS: Windows XP
parsing buildfile d:\temp\build.xml with URI = file:/d:/temp/build.xml
Project base dir set to: d:\temp
parsing buildfile jar:file:/C:/ProgramFiles/Java/apache-ant-1.8.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/ProgramFiles/Java/apache-ant-1.8.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `simplestCopy' is [simplestCopy]
Complete build sequence is [simplestCopy, ]
simplestCopy:
[mkdir] Skipping d:\temp\test because it already exists.
java.net.ConnectException: Connection refused: connect
BUILD FAILED
d:\temp\build.xml:7: Warning: Could not find resource url "http://ant.apache.org/index.html" to copy.
at org.apache.tools.ant.taskdefs.Copy.execute(Copy.java:487)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
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 org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
at org.apache.tools.ant.Project.executeTarget(Project.java:1366)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1249)
at org.apache.tools.ant.Main.runBuild(Main.java:801)
at org.apache.tools.ant.Main.startAnt(Main.java:218)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 1 second
Any ideas how to fix?
Thanks for help...
Use the setproxy task: http://ant.apache.org/manual/Tasks/setproxy.html
I started the tomcat server and then issue the command and it works