Unable to run java programs! NoClassDefFoundError?

I am a .NET developer, but for my current project I need to use Java Caja, a Java project. Uhhh!

I followed the manual on http://code.google.com/p/google-caja/wiki/RunningCaja on my Windows computer, but could not start the program. The command line they offer did not work, so I wrote cd'd to the ant -jars directory and tried to run the plugin.jar file:

D:\java\caja\svn-changes\pristine\ant-jars>java -cp . -jar pluginc.jar -i test.htm Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException at com.google.caja.plugin.PluginCompilerMain.<init>(PluginCompilerMain.java:78) at com.google.caja.plugin.PluginCompilerMain.main(PluginCompilerMain.java:368) Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException 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:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 2 more 

What does it mean?

I also tried the file: /// d: / java / caja / svn-changes / pristine / ant -jars / test.htm instead of test.htm. Looking at the source, it seems that the file parameter is Uri ...

I also tried to run IKVM on pluginc, and then did not worry about java, but that also raised a ClassDefNotFoundException ...

thanks!

Edit: thanks everyone for the help so far :) still stuck. please continue with me, this may be the beginning of a .net transition to the great OSS technology!

 d:\java\caja\svn-changes\pristine\ant-jars>java -cp .\*.* com.google.caja.plugin.PluginCompilerMain => NoClassDefFoundError: /\commons-cli/jar D:\java\caja\svn-changes\pristine\ant-jars>java -cp .\*.*;..\third_party\java\jakarta_commons\*.* com.google.caja.plugin.PluginCompilerMain => Could not find the main class: com.google.caja.plugin.PluginCompilerMain 

Is there a way to run it based on the code in the build.xml file?

+6
java noclassdeffounderror google-caja
source share
4 answers

Java is trying to load the org.apache.commons.cli.ParseException class, but it cannot find it. This indicates that you are not correctly configuring the class path.

This particular class comes from the Apache Commons CLI library, so look at a jar named cli.jar or commons-cli.jar. It can be in a separate lib directory. If there are other banks in one place, you may also have to add them.

Edit: looking at the build.xml file, it uses the following class path:

  <path id="classpath.web"> <pathelement path="${third_party}/java/jsdk2.1/servlet.jar"/> <pathelement path="${third_party}/java/jaf/activation.jar"/> <pathelement path="${third_party}/java/javamail/mail.jar"/> <pathelement path="${third_party}/java/jetty/lib/jetty.jar"/> <pathelement path="${third_party}/java/jetty/lib/jetty-util.jar"/> </path> <path id="classpath.compile"> <path refid="classpath.web"/> <pathelement path="${third_party}/java/jakarta_commons/commons-cli.jar"/> <pathelement path="${third_party}/java/json_simple/json_simple.jar"/> <pathelement path="${third_party}/java/rhino/js.jar"/> <pathelement path="${third_party}/java/xerces/xercesImpl.jar"/> <pathelement path="${jars}/htmlparser.jar"/> </path> <path id="classpath.run"> <pathelement path="${lib}"/> <path refid="classpath.compile"/> </path> 

Therefore, when calling java, you will need to include all of these banks in the cp argument.

Edit # 2: As Ash noted, you cannot use -cp with -jar , so you will need to put pluginc.jar in the classpath and manually specify the main class (so java -cp ...;pluginc.jar com.google.classname -i etc ). It would be easier to get an ant job than doing it all manually;)

+10
source share

Also note that when using the -jar parameter -jar all other CLASSPATH settings are ignored. Cm. http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html :

When you use this parameter, the JAR file is the source of all user classes, and other parameters of the user class path are ignored.

+6
source share

try it

 java -classpath .;%classpath%; -jar pluginc.jar -i test.htm 
0
source share

It looks like you need to put the path in ApacheCommons to your CLASSPATH .

0
source share

All Articles