I know this is a very common question, but I tried googling and got no helpful result. I\'m trying to make a jar out of my \"Main.class\" file (made in NetBeans, but I\'m not tr
Create a file called well, anything really, but we'll call it manifest.txt
Open manifest.txt and type:
Main-Class: Main
then to create your jar, type
jar cfm trovanum.jar manifest.txt *.class
And it should run fine.
You can use the -e
option of jar to specify the entry point, i.e. the main class. For example:
D:\NetBeans\trovanum3\build\classes> jar cfe trovanum.jar trovanum3.Main trovanum3\*.class
Saves fiddling with the manifest if that's all you need in there. Note the working directory is one up from that quoted in your question. Otherwise the Main class is created at the top-level in the jar, rather than in a directory that reflects the package in which it should reside. jar -tvf
should then show something like this:
0 Thu Oct 21 22:34:30 BST 2010 META-INF/
80 Thu Oct 21 22:34:30 BST 2010 META-INF/MANIFEST.MF
488 Thu Oct 21 22:18:24 BST 2010 trovanum3/Main.class
-e
Sets entrypoint as the application entry point for stand-alone applications bundled into executable jar file. The use of this option creates or overrides the Main-Class attribute value in the manifest file. This option can be used during creation of jar file or while updating the jar file. This option specifies the application entry point without editing or creating the manifest file.
You need to specify the Main-Class property in the manifest file: Understanding the Manifest. This usually means you need to add the manifest file yourself instead of letting it be added automatically.
By the way you can always run your code without a manifest like this:
java -cp path/to/myJar.jar my.package.MyClass
The manifest is required when you want to run it like this:
java -jar path/to/myJar.jar
Create executable jar( and not plain jar file). You get this option in eclipse while exporting jar file. I was facing same issue and it resolved once I created the executable jar.
Create batch file as : java -jar "abc.jar" ..
Extract the mainifest file.
Add an extra line so it says :
Manifest-Version: 1.0
Created-By: 1.6.0_22 (Sun Microsystems Inc.)
Main-Class: Main
Make sure there is two newline characters at the end.
Update the jar file. You could either have edited the Manifest in the jar file with WinRAR, 7-zip, etc. or you could have deleted the original jar (after extracting and editing) then ran
jar -cmf MANIFEST.MF trovanum.jar *.class
Then it would use your newly modified manifest in the jar.
You need to set the Main-Class attribute in the manifest of your jar. See the java tutorial link below for details.
http://download.oracle.com/javase/tutorial/deployment/jar/appman.html