Tuesday, October 18, 2011

Creation of jar file using command line (By Shymaa Tarek)




create a folder name this folder the same as the package name (in this example the package and folder are called mypkg).
put your file .class in this folder
first create file called manifest.txt  out side the new folder(mypkg) leave this file empty.
Write this command where it will create a jar file called ExecutableJar.jar

   jar cmf manifest.txt ExecutableJar.jar  mypkg

now the jar file is created if you run this jar file with this command
  java -jar ExecutableJar.jar

you will have this error message

"Failed to load Main-Class manifest attribute from ... .jar"

open the manifest file with the archive manager
  remove these two lines:

  Manifest-Version: 1.0
  Created-By: 1.6.0_20 (Sun Microsystems Inc.)
  
   add this line :

   Main-Class: PackageName.ClassName
   
 1. Make sure that you left white space after   :
  2.you have to press enter after finishing the line

Source: