无法让java程序运行!没有发现类定义错误?

发布于 2024-09-01 23:37:55 字数 1923 浏览 3 评论 0原文

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

我已按照 http://code.google.com/p/ 上的指南进行操作在我的 Windows 计算机上运行 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

这是怎么回事?

我还尝试过 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 文件中的代码吗?

I'm a .NET developer, but for my current project I need to use Google Caja, a Java project. Uh-oh!

I've followed the guide at http://code.google.com/p/google-caja/wiki/RunningCaja on my windows machine, but can't get the program to run. The command line they suggest didn't work, so I cd'd into 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

Whats that all about?

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

I've also tried running IKVM on pluginc and then not worrying about java, but that came up with the ClassDefNotFoundException too...

thanks!

edit: thanks everyone for the help so far :) still stuck. please persevere with me, this might be the start of a .net developer switching to beautiful OSS technologies!

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 some way I can get it to run given the code in the build.xml file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

囍笑 2024-09-08 23:37:55

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>

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

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

Java's trying to load the org.apache.commons.cli.ParseException class, but it can't find it. This suggests you're not setting the classpath properly.

That particular class comes from the Apache Commons CLI library, so have a look around for a jar named something like cli.jar or commons-cli.jar. It may be in a separate lib directory. If there are other jars in the same place, you'll probably need to add them, too.

Edit: looking at the build.xml file, it 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>

So you'll need to include all of those jars in the cp argument when calling java.

Edit #2: As Ash pointed out, you can't use -cp with -jar, so you'll need to put the pluginc.jar on the classpath as well and manually specify the main class (so java -cp ...;pluginc.jar com.google.classname -i etc). It'd probably be easier to get ant working than to do all of this manually ;)

洋洋洒洒 2024-09-08 23:37:55

另请注意,当您使用 -jar 选项时,所有其他 CLASSPATH 设置都将被忽略。请参阅http://java.sun.com/javase/6/docs/technotes/tools/windows /java.html

当您使用此选项时,JAR 文件是所有用户类的源,并且其他用户类路径设置将被忽略。

Also note that when you use the -jar option, all other CLASSPATH settings are ignored. See http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html:

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

就是爱搞怪 2024-09-08 23:37:55

试试这个

java -classpath .;%classpath%; -jar pluginc.jar -i test.htm

Try this

java -classpath .;%classpath%; -jar pluginc.jar -i test.htm
烂人 2024-09-08 23:37:55

看起来您需要将 ApacheCommons 库的路径放入 CLASSPATH

Looks like you need to put the path to ApacheCommons library to your CLASSPATH.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文