jar -cfm [name of the jar file] [name of the manifest]
Flags Description:
c: Create new archive
f: Specify the archive name
m: include manifest
* means include all the files in the current folder and all the sub folders.
The manifest file look something like this:
Main-Class: [name of the main class along with the package details]
Example
If your project has two files a.class and main.class. which are placed in a package(abc.def). Then the manifest would look like this(mainClass.mf):
___________________
Main-Class: abc.def.main
___________________
and the command to create an executable jar will be
jar -cfm test.jar mainClass.mf *
Everything works ok if you are not using any external jars but the problem arises when you have externals jar like you have used the logging component log4j. The manifest attribute Class-Path attribute in which you can mention the paths of the external jars, but i tried it for log4j but it didn't work it gives me error 'Logger Class Def Not Found'. I had created the following manifest for that (Keeping the above exapmle in mind)
__________________
Main-Class: abc.def.main
Class-Path: lib\log4j.jar
__________________
but this didn't worked.
Then i came across a work around for this, which is you create a jar file of your project class files without adding the extenal libaries ie. using the following same manifest:
___________________
Main-Class: abc.def.main
___________________
Place the created jar files along with the external jar files in another folder and then use the following manifest to create the final jar file.
____________________
Main-Class: abc.def.main
Class-Path: main\test.jar lib\log4j.jar
____________________
Notice that test.jar is the jar file of your actual project. the final jar created using the above manifest will work for you.