双击无法运行jar文件

时间:2012-01-07 07:30:27

标签: java eclipse jar

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

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

Eclipse也运行良好。

其他jar文件,不是由我编写的,只需双击就可以正常运行。

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

我已经检查过jar与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文件 - >当前项目的启动配置&第一个单选按钮 - >完成

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

1 个答案:

答案 0 :(得分:4)

创建一个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