Cannot run jar file from double click

If I double-click on the jar file, I get "Can't find the main class: HelloWorld. The program will exit."

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

It also works great with Eclipse.

Other jar files not written by me work fine when double clicked.

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

I checked that the banks are associated with javaw.exe

a jar that I cannot start from a double click and a project folder with a source from Eclipse

"jar that I can run from a double click"

To create a jar file, I use Eclipse-> File-> Export-> Java-> Runnable JAR file-> Current project startup configuration and first switch -> end

In addition, other people get the same error when trying to start my jar.

+1
source share
1 answer

Creating a jar file is not very difficult. But creating a downloadable jar file requires more steps: create a manifest file containing the start class, create a target directory, and archive 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

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

+4
source

All Articles