Click to publicize, if you like this article :
As per previous article, i am considering that you have already compiled the program.
go to the folder “classes” and create a manifest file named as “manifest.txt” and add the name of starting java class as shown below.
or, run below command in command prompt
echo Main-Class: com.g2.ExecJar.Start >manifest.txt
now, run the command to create a jar file:
jar cvfm First.jar manifest.txt com\g2\ExecJar\*
- “jar” is the tool provided by the jdk to create the jar file.
- “cvfm” is the argument. check this documentation to know about all the arguments provided by the java.
- “manifest.txt” name of the manifest file. (Remember file must have carriage return value or one blank line at End of document).
- “com\g2\ExecJar\*” tells the tool that include all the files (*.class) in jar.
To run the jar, in command prompt, enter command:
java -jar First.jar
Question :Why the jar file is not executing ? it opens in winrar instead of execution.
Answer : This problem occurs mainly after installation of the winrar. To change the program for opening jar file, run below code in batch file:
@echo OFF assoc .jar=jarfile ftype jarfile="D:\RMB\jdk\bin\javaw.exe" -jar "%1" %* pause