【问题标题】:Can't run a jar file from the double click [closed]无法通过双击运行 jar 文件 [关闭]
【发布时间】:2012-02-04 18:57:10
【问题描述】:

如果我双击我的 jar 文件,我会得到“找不到主类:HelloWorld。程序将退出。”

当我从命令行以“java -jar HelloWorld.jar”运行它时,它工作正常。

它在 Eclipse 中也可以正常运行。

其他jar文件,不是我写的,双击运行正常。

我已将 CLASSPATH 变量设置为“。”并将 jdk 路径添加到 PATH 变量中。

我已经检查了 jars 是否与 javaw.exe 相关联

"the jar that I can't run from the double click & the project folder with the source from the Eclipse "

"friend's jar that I can run from the double click"

要制作一个 jar 文件,我使用的是 Eclipse->File->Export->Java->Runnable JAR file->Current project's launch configuration & the first radio button->finish

另外,其他人在尝试运行我的 jar 时也会遇到同样的错误。

【问题讨论】:

  • 您是否尝试过从命令提示符手动创建您的 jar 文件,方法是提供在其中定义您的 Main-Class 的清单文件。试试看。问候
  • 刚刚做了,双击时出现同样的错误,当我从命令promt运行它时它工作了
  • jar 文件中有什么,清单是什么样的?你能把它放在网上任何地方让我们看看吗?
  • 乔恩,你能看到我的问题中的第一个链接,其中包含 jar-fle 本身和包含源代码的 Eclips 项目文件夹吗?

标签: java eclipse jar


【解决方案1】:

创建一个 jar 文件并不是很困难。但是创建一个可启动的 jar 文件需要更多的步骤:创建一个包含启动类的清单文件,创建目标目录并归档文件。

echo Main-Class: oata.HelloWorld>myManifest
md build\jar
jar cfm build\jar\HelloWorld.jar myManifest -C build\classes .
java -jar build\jar\HelloWorld.jar

检查:http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html

【讨论】:

  • 我的类名不是“oata.HelloWorld”,而是“HelloWorld”,因此得到“错误:无法找到或加载主类 oata.Helloworld”。
  • 查看链接并进行相应的更改。我建议先使用命令行来测试你的 jar 应用程序。
  • 这跟我有什么关系?我是从 Eclipse 中创建 jar 文件,而不是使用 ant 的命令提示符,这不像我在命令提示符中做错了。
  • @Makc 相信我,使用命令提示符更容易做到这一点
  • @JesusRamos 我不信任你
猜你喜欢
  • 2017-02-14
  • 2016-02-19
  • 1970-01-01
  • 1970-01-01
  • 2023-02-02
  • 1970-01-01
  • 1970-01-01
  • 2020-01-23
  • 1970-01-01
相关资源
最近更新 更多