Monday, March 21, 2011

Creating Executable jar in Java

    Jar files are created using the jar.exe utility program from JDK.  You can make your jar file executable by defining the main class.  For thist, you  need to create a manifest file.  A manifest file is a one-line text file with a "Main-Class" directive.  For example:
Main-Class: <MainClassName>
This line must end with a newline.
For example---

  Step to create executablr jar filr ---


  1. Create a new folder MyApp and put all the java files.
  2. Now navigate to this folder from cmd and compile all files.( javac *.java)
  3. Let we hava Main.java,Class1.java and Class2.java 
  4. Write a manifest.txt file(write the statement  ,Main-Class: Main)
  5. Now run the jar utility(jar cvfm myjar.jar manifest.txt *.class)
  6. Now test your jar(myjar.jar)

1 comment: