无法让java程序运行!NoClassDefFoundError的?

mci*_*321 7 java noclassdeffounderror google-caja

我是.NET开发人员,但对于我目前的项目,我需要使用Google Caja,这是一个Java项目.嗯,哦!

我在Windows机器上的http://code.google.com/p/google-caja/wiki/RunningCaja上按照指南操作,但无法运行程序.他们建议的命令行不起作用,所以我进入ant-jars目录并尝试运行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
Run Code Online (Sandbox Code Playgroud)

那是怎么回事?

我也尝试过file:/// d:/java/caja/svn-changes/pristine/ant-jars/test.htm而不是test.htm.看来源,似乎文件参数是一个Uri ......

我也尝试在pluginc上运行IKVM,然后不用担心java,但是它也提出了ClassDefNotFoundException ......

谢谢!

编辑:感谢大家的帮助到目前为止:)仍然卡住了.请坚持下去,这可能是.net开发人员转向美丽的OSS技术的开始!

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
Run Code Online (Sandbox Code Playgroud)

鉴于build.xml文件中的代码,有什么方法可以让它运行吗?

Chr*_*ris 11

Java试图加载org.apache.commons.cli.ParseException类,但是找不到它.这表明您没有正确设置类路径.

该特定类来自Apache Commons CLI库,因此请浏览一个名为cli.jar或commons-cli.jar的jar.它可能位于单独的lib目录中.如果在同一个地方有其他罐子,你可能也需要添加它们.

编辑:查看build.xml文件,它使用以下类路径:

  <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>
Run Code Online (Sandbox Code Playgroud)

因此,cp在调用java时,您需要在参数中包含所有这些jar .

编辑#2:灰分指出,你不能使用-cp-jar,所以你需要把pluginc.jar在类路径中,并手动指定主类(所以java -cp ...;pluginc.jar com.google.classname -i etc).让蚂蚁工作比手动完成所有这些更容易;)

  • @ mcintyre321 - 听起来你的提示/ shell正在扩展`*`,而不是将它传递给Java.我有一段时间没有触及Windows命令提示符,但可能尝试将其放在引号中?(例如,`java -cp".\*"com.google ...`) (2认同)

Ash*_*Ash 6

另请注意,使用该-jar选项时,将忽略所有其他CLASSPATH设置.看到http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html:

使用此选项时,JAR文件是所有用户类的源,并忽略其他用户类路径设置.