Manual process to make a executable JAR
1. Make a Java project, make classes and get compiled classes.
2. Make a folder named "META-INF" in the Project folder and create a file named "MENIFEST.MF" under this folder.
3. Edit file MENIFEST.MF and provide following details, and save the file.
Manifest-Version: 1.0
Main-Class: com.genius.Hello
Here, main class is the class name having the main method from where your java project execution starts.
4. Create the Jar file in which you can specify the menifest file name :
Example
jar cvf c:\myapp\genius.jar *.class
jar cvfm c:\myapp\genius.jar MENIFEST.MF *.class
jar cvfm c:\myapp\genius.jar manifest.txt *.class
If menifest file is having any other name
5. Run the JAR file
java -jar c:\myapp\genius.jar
We can run it thorugh a bat file (using double click) also, just to see output after running the JAR.
Example contents of bat file
java -jar c:\myapp\genius.jar
pause
Making a executable JAR using Eclipse
1. Right click on project and click Export.
2. Select Java - Jar file. Click Next.
3. Click Browse... and provide location and Jar file name to be created. Click Next.
4. Click Next.
5. In this step, choose whether you want to generate the menifest file or choose already created menifect file from your project.
6. Also, select the Main class, which is having main method as the starting point of project execution.
7. Click Finish.
Repeat the steps given above for running the JAR file.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.