Unable to make Java program run! NoClassDefFoundError?
I am. Net developers, but for my current project, I need to use Google Caja, which is a java project Well, oh!
On a Windows machine, I follow http://code.google.com/p/google-caja/wiki/RunningCaja , but cannot run the program The command line they suggested didn't work, so I went to the ant jars directory and tried to run plugin jar:
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's going on?
I also tried 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 a URI
I also try to run ikvm on pluginc and don't worry about Java, but it also puts forward classdefnotfoundexception
thank you!
Editor: Thank you for your help. So far:) is still stuck Please hold on, it may be Net developers turn to the beginning of beautiful 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
Whereas build Is there any way to make the code in the XML file run?
Solution
Java tried to load org apache. commons. cli. Parseexception class, but it cannot be found This indicates that you have not set the classpath correctly
This particular class comes from the Apache commons cli library, so browse for a class called cli Jar or commons cli Jar It may be located in a separate lib directory If there are other cans in the same place, you may need to add them as well
Editing: viewing build XML file, which uses the following classpath:
<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 need to include all these jars in the CP parameter
Edit #2: as ash pointed out, you can't use - CP with - jar, so you need to use pluginc Jar on the classpath and manually specify the main class (so Java - CP...; pluginc.jar com.google.classname - I etc.) Making ants work is easier than doing all this manually;)