gpt4 book ai didi

java - 无法运行 java 程序! NoClassDefFoundError?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:05:30 25 4
gpt4 key购买 nike

我是 .NET 开发人员,但对于我当前的项目,我需要使用 Java 项目 Google Caja。呃哦!

我已按照 http://code.google.com/p/google-caja/wiki/RunningCaja 上的指南进行操作在我的 Windows 机器上,但无法让程序运行。他们建议的命令行不起作用,所以我进入 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

这是怎么回事?

我也试过 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

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

最佳答案

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

该特定类来自 Apache Commons CLI 库,因此请查看是否有名为 cli.jar 或 commons-cli.jar 之类的 jar。它可能位于单独的 lib 目录中。如果同一位置还有其他 jar ,您可能也需要添加它们。

编辑:查看 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>

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

编辑 #2:正如 Ash 所指出的,您不能将 -cp-jar 一起使用,因此您需要将 pluginc. jar 以及手动指定主类(所以 java -cp ...;pluginc.jar com.google.classname -i etc)。让 ant 工作可能比手动完成所有这些工作更容易;)

关于java - 无法运行 java 程序! NoClassDefFoundError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2865183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com