Often you will want to specify a manifest, like so:
jar -cvfm myJar.jar myManifest.txt myApp.class
Which reads: "create verbose jarFilename manifestFilename", followed by the files you want to include. Verbose means print messages about what it's doing.
Note that the name of the manifest file you supply can be anything, as jar will automatically rename it and put it into the right directory within the jar file.
Ok this is the solution I would have liked to find, instead here I write it:
First create the directory structure corresponding to the package defined for the .java file, if it is my.super.application create the directory "my" and inside it "super" and inside it the .java file "App.java"
Notice the above will include multiple libraries, if under windows use "," to separate multiple files otherwise under GNU/Linux use ":"
To create a jar file
jar -cvfe App.jar App my/app/
the above will create the application with its corresponding Manifest indicating the App as the main class.
Including the required libraries inside the jar file is not possible using java or jar command line parameters.
You can instead:
manually extract libraries to the root folder of the jar file
use an IDE such as Netbeans and insert a rule inside post-jar section of nbproject/build-impl.xml to extract the libraries inside the jar. See below.
<target name="-post-jar">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
<jar jarfile="${dist.jar}" update="true">
<zipfileset src="${dist.jar}" includes="**/*.class" />
<zipfileset src="${file.reference.iText-1.0.8.jar}" includes="**/*"/>
<zipfileset src="${file.reference.itextpdf-3.2.1.jar}" includes="**/*"/>
</jar>
</target>
the file.reference names are found inside project.properties file after you added the libraries to the Netbeans IDE.
$ ls | grep .java | xargs -I {} javac {} ; jar -cf myJar.jar *.class
Which will grab all the .java files ( ls | grep .java ) from your current directory and compile them into .class (xargs -I {} javac {}) and then create the jar file from the previously compiled classes (jar -cf myJar.jar *.class).
Perhaps the most beginner-friendly way to compile a JAR from your Java code is to use an IDE (integrated development environment; essentially just user-friendly software for development) like Netbeans or Eclipse.
Create a project in your IDE and put your Java files inside of the project folder.
Select the project in the IDE and export the project as a JAR. Double check that the appropriate java files are selected when exporting.
You can always do this all very easily with the command line. Make sure that you are in the same directory as the files targeted before executing a command such as this:
javac YourApp.java
jar -cf YourJar.jar YourApp.class
...changing "YourApp" and "YourJar" to the proper names of your files, respectively.
If you have one simple main class(let's say Count.class), and want a jar with a MANIFEST file that points to this class as the entry point, you can do this: