Create Executable jar file of classes in package

Get articles everyday as a email directly to your inbox:
Click to publicize, if you like this article :

For the source code, please refer 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.

Main-Class: com.g2.ExecJar.Start

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\*


Where,

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
You can leave a response, or trackback from your own site.