Can't run a jar file from the double click [closed]

空扰寡人 提交于 2020-01-16 04:23:21

问题


If I double-click on my jar file, I get "Could not find the main class: HelloWorld. Program will exit."

When I run it from the command line as "java -jar HelloWorld.jar" it works fine.

It also runs fine from the Eclipse.

Other jar files, not written by me, run fine from the double click.

I have set CLASSPATH variable to "." and added the jdk path to the PATH variable.

I have checked that jars are associeted with the 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"

To make a jar file I'm using Eclipse->File->Export->Java->Runnable JAR file->Current project's launch configuration & the first radio button->finish

Also, other people get the same error when trying to run my jar.


回答1:


Creating a jar-file is not very difficult. But creating a startable jar-file needs more steps: create a manifest-file containing the start class, creating the target directory and archiving the files.

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

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



来源:https://stackoverflow.com/questions/8768122/cant-run-a-jar-file-from-the-double-click

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!