问题
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