使用类路径在 Snow Leopard 上运行 Jar

发布于 2024-10-17 06:38:44 字数 863 浏览 2 评论 0原文

我正在运行雪豹,我刚刚在 Eclipse 上编写了一个 Java 类。 eclipse 项目引用了一个用户库,该库本身指向我在系统中某处的一堆 jar 文件。当我通过 eclipse 运行该应用程序时,一切都很顺利。 然后,我将该类导出为 jar 文件,并尝试通过键入以下内容从终端运行它:

java - jar myApp.jar

它抛出 java.lang.NoClassDefFoundError 异常,这意味着它找不到我尝试引用的库。 知道我的用户库 jar 文件位于 /Users/myname/tempJars 中,我还尝试使用 -cp 选项提及类路径 (java -cp /Users/myname/tempJars -jar myApp.jar) 或直接在清单文件中引用它。两次尝试都失败了,并且错误是相同的。 这些库是Java 1.5库,所以我想我应该尝试通过JAVA_HOME环境变量引用另一个java版本。我构建了以下脚本:

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$CLASSPATH:/Users/myname/tempJars

java -jar myApp.jar

同样,不好。我用谷歌搜索了如何在雪豹中执行 jar,在某些地方发现了 32/64 位的大问题,甚至尝试使用 -d32 选项执行,但仍然无济于事。 由于相同的代码在 Eclipse 中执行得很好,因此我非常确信这只是设置 JVM 以便它正确包含用户库的问题。

有人能帮我解决这个问题吗?

提前致谢。

I'm running snow leopard and I just wrote a Java class on eclipse. The eclipse project references a user library which itself points to a bunch of jar files I've got somewhere in the system. When I run the app through eclipse, everything goes smoothly.
Then I export the class as a jar file and try to run it form the terminal by typing:

java - jar myApp.jar

It throws a java.lang.NoClassDefFoundError exception, meaning that it can't find the libraries I try to reference.
Knowing that my user library jar files are in /Users/myname/tempJars, I also tried to either mention the classpath using the -cp option
(java -cp /Users/myname/tempJars -jar myApp.jar) or to directly reference it in the manifest file. Both attempts failed and the error is the same.
These libraries are Java 1.5 libraries, so I thought I should try and reference another java version by mean of the JAVA_HOME environment variable. I built the following script:

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$CLASSPATH:/Users/myname/tempJars

java -jar myApp.jar

Again, no good. I googled how to execute jars in snow leopard, found the 32/64 bit big deal in some places and even tried executing with the -d32 option, but still to no avail.
Since the same code executes just fine in eclipse, I'm pretty convinced it's just a matter of setting up the JVM so that it includes the user libraries correctly.

Could anyone help me with this?

Thanks in advance.

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

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

发布评论

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

评论(1

酒中人 2024-10-24 06:38:44

您需要在类路径上列出 JAR 本身,而不仅仅是包含它们的目录。 (列出目录是为了当您在包层次结构中取消归档 .class 文件时)

您可能需要执行 -cp /Users/myname/tempJars/libA.jar:/.../libB.jar

我相信某些(但可能不是全部)JVM 支持通配符,因此 -cp /Users/myname/tempJars/* 或其某些变体可能会起作用。

You need to list the JARs themselves out on the classpath, not just the directory containing them. (Listing the directory is for when you have unarchived .class files in the package hierarchy lying around)

You will probably need to do -cp /Users/myname/tempJars/libA.jar:/.../libB.jar

I believe some (but potentially not all) JVMs support wildcards so -cp /Users/myname/tempJars/* or some variant thereof may work.

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