Reputation: 3654
I'm trying to create a jar with the jar tool. Using the following command
jar.exe cmfv manifest.txt lol.jar Main.class
This generates a jar with the following manifest:
Manifest-Version: 1.0
Created-By: 1.7.0_03 (Oracle Corporation)
Main-Class: Main
When I run the jar from command line (java -jar lol.jar) it runs fine. But when I double click the jar in my folder it gives an error: "Could not find the main class: Main.Program will exit."
What could be causing this?
After trying some stuff out the Manifest currently looks like this:
Manifest-Version: 1.0
Class-Path: .
Created-By: 1.7.0_03 (Oracle Corporation)
Main-Class: code.Main
The Main class has a package declaration added. Inside the jar the 'code' folder/package is added. Still have the same error though.
Upvotes: 2
Views: 769
Reputation: 3847
What is the file association with the .jar extensions?
Double click the jar file should make the jar run woth the javaw command.
Try making jar files to be executed by default with javaw.
Also take a look at this: http://www.wikihow.com/Run-a-.Jar-Java-File
Upvotes: 0
Reputation: 2653
You need to put the Main class in your classpath. When you run it from the command line, your current directory is auto-added to your classpath, this is why it works from there. When you double click it, you are not specifying the path to the jar as in the classpath. There are ways to add the class to your classpath in your manifest. Below is an example of one of my jars. lib is a folder within the jar, com/sample/CommandLineClient.class is my main class.
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.5.0_12-b04 (Sun Microsystems Inc.)
Class-Path: lib/args4j-2.0.19.jar lib/axis.jar lib/axis-ant.jar lib/commons-discovery-0.2.jar lib/commons-logging-1.0.4.jar lib/jaxrpc.jar lib/log4j-1.2.8.jar lib/saaj.jar lib/wsdl4j-1.5.1.jar
Main-Class: com.sample.CommandLineClientSysIn
Upvotes: 0
Reputation: 35106
You should put your Main class into a package, and adjust your manifest correspondingly. That should solve the problem
Upvotes: 1