类在类路径中时出现 ClassDefNotFoundError

发布于 2025-01-01 00:46:29 字数 1408 浏览 1 评论 0原文

我正在尝试运行 ParSeMiS。根据文档,它需要在其 lib 目录中提供 antprefuseantlr jar。我已经把所有需要的罐子都放进去了。但是,当我尝试运行它时,出现以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: antlr/TokenStreamException
    at de.parsemis.miner.environment.Settings.parseFileName(Settings.java:198)
    at de.parsemis.miner.environment.Settings.parseOption(Settings.java:312)
    at de.parsemis.miner.environment.Settings.parse(Settings.java:170)
    at de.parsemis.miner.environment.Settings.parse(Settings.java:122)
    at de.parsemis.Miner.run(Miner.java:358)
    at de.parsemis.Miner.main(Miner.java:61)
Caused by: java.lang.ClassNotFoundException: antlr.TokenStreamException
    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:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 6 more

现在,我已验证 antlr/TokenStreamException.class 存在于 antlr jar 中。我尝试通过导出 CLASSPATH 变量并通过 -cp 开关设置它来手动将 jar 添加到类路径中。然而,这些都不起作用,我仍然遇到这个异常。有人能帮我弄清楚出了什么问题吗?谢谢。

I'm trying to run ParSeMiS. According to the documentation, it requires ant, prefuse and antlr jars to be available in its lib directory. I've put all the required jars in it. However, when I try to run it, I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: antlr/TokenStreamException
    at de.parsemis.miner.environment.Settings.parseFileName(Settings.java:198)
    at de.parsemis.miner.environment.Settings.parseOption(Settings.java:312)
    at de.parsemis.miner.environment.Settings.parse(Settings.java:170)
    at de.parsemis.miner.environment.Settings.parse(Settings.java:122)
    at de.parsemis.Miner.run(Miner.java:358)
    at de.parsemis.Miner.main(Miner.java:61)
Caused by: java.lang.ClassNotFoundException: antlr.TokenStreamException
    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:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 6 more

Now, I've verified that antlr/TokenStreamException.class is present in the antlr jar. I have tried adding the jar manually to the classpath by both exporting the CLASSPATH variable and setting it via the -cp switch. However, none of that works, and I still get this exception. Can anybody help me figure out what's wrong? Thanks.

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

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

发布评论

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

评论(2

伪心 2025-01-08 00:46:29

问题是您使用的 -jar 会忽略您的 CLASSPATH 环境变量。您应该在清单中列出您的依赖项,如此处所示,例如

Class-Path: lib/ant.jar lib/antlr-3.4-complete.jar lib/prefuse.jar

(但是,它应该仍然可以使用显式的-cp选项。我的猜测是,您在指定该选项时出错了,并假设这是相同的根本原因由于使用环境变量时失败。)

The problem is that you're using -jar which ignores your CLASSPATH environment variable. You should list your dependencies in the manifest, as shown here, e.g.

Class-Path: lib/ant.jar lib/antlr-3.4-complete.jar lib/prefuse.jar

(It should have still worked with an explicit -cp option, however. My guess is that you got something wrong when specifying that, and assumed it was the same underlying cause as the failure when using the environment variable.)

空‖城人不在 2025-01-08 00:46:29

我意识到这个问题很老了,但我遇到了完全相同的问题并找到了这个线程。对于后代,我发布了我最终如何让它运行:

如上所述,当使用 -jar 运行时,java 显然会忽略类路径。所以不要使用 -jar 运行它。相反,将 jar 包含在路径中并直接运行该类。经过一番研究,以下内容应该可以工作(路径位于我的 Ubuntu 12.10 系统上):

java -cp /usr/share/java/antlr.jar:/full/path/to/parsemis.jar de.parsemis.Miner

然后您可以将选项传递给上面的内容。可以确定您使用完整路径,并且没有像 ~/foo 这样的快捷方式,因为它们显然不会扩展。

当然,如果你像我一样使用点格式的图表,它会很早就因为抱怨“意外的字符0xA”而死掉,但至少它会更进一步。

I realize this question is very old, but I just had exactly the same problem and found this thread. For posterity, I'm posting how I did eventually get it to run:

As mentioned above, when running with -jar, java apparently ignores the class path. So don't run it with -jar. instead include the jars in the path and run the class directly. Poking around, the following should work (paths are on my Ubuntu 12.10 system):

java -cp /usr/share/java/antlr.jar:/full/path/to/parsemis.jar de.parsemis.Miner

You can then pass in options to the above. Maye sure you use full paths, and no shortcuts like ~/foo, as they apparently don't expand.

Of course, if you're using a Dot-formatted graph like I am, it dies very early on complaining of "unexpected char 0xA", but at least it gets further.

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