Saturday, April 4, 2015

Creating a jar file in Command Prompt

The following are the steps to create the jar from command prompt
1.  Start Command Prompt.
        Navigate to the folder that holds your class files:
        C:\>cd \myproject
2.  Ignore this step if you already set the java path in environment variables
    To Check if it is already done run the below command
        echo %path
Set path to include JDK’s bin.  For example:
        C:\myproject> path c:\Program Files\Java\jdk1.7.0_25\bin;%path%                            
3.  Compile your class(es):
        C:\myproject> javac *.java
4.  Create a manifest file and your jar file:
        C:\myproject> echo Main-Class: MyMainClass >manifest.txt
        C:\myproject> jar cvfm MyJar.jar manifest.txt *.class
        - c for creating jar
        - v for verbos for displaying jar information on command prompt while jar itself
        - f for jar name
        - m for referring manifiest file                            
5.  Test your jar:
        c:\myproject> java -jar MyJar.jar

No comments:

Post a Comment