How can i make a jar file from both the command line and Netbeans 6.7?
4 Answers
Using the JAR command:
jar cf jar-file input-file(s)
Using Maven:
<packaging>jar</packaging>
Using Ant:
<jar destfile="${dist}/lib/app.jar" basedir="${build}/classes"/>

- 76,436
- 32
- 213
- 198

- 51,004
- 28
- 112
- 141
-
jar cf jar-file input-file(s) in the input-file we have to write the name of file right? like for example jar cf jar-file Convert.java ??? – Sundhas Feb 01 '10 at 19:26
-
1@Sundhas - you want to put `.class` files in your JAR, not source files. – danben Feb 01 '10 at 19:34
-
1@Sundhas - Here is a concrete example "jar cf my.jar My.class" – Taylor Leese Feb 01 '10 at 20:12
-
Right get it now :) Thanks alot Danben and Taylor L. – Sundhas Feb 02 '10 at 19:05
-
I have one more question.. How to execute that jar file via notepad? and whats the manifest folder all about? what it does? – Sundhas Feb 02 '10 at 19:15
-
To execute a jar file: java -jar app.jar You will also need to have a MANIFEST.MF file in the META-INF directory that define the Main-class like this: Manifest-Version: 1.0 Created-By: 1.6.0 (Sun Microsystems Inc.) Main-Class: MyPackage.MyClass – Taylor Leese Feb 02 '10 at 19:38
-
Take a look at this link: http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html – Taylor Leese Feb 02 '10 at 19:38
jar cf jar-file input-files
http://java.sun.com/developer/Books/javaprogramming/JAR/basics/build.html

- 30,349
- 24
- 103
- 144
Command line:
jar cf jarfile [ -C dir ] inputfiles
Make sure you are jar
-ing from the root of the directory matching your package hierarchy, rather than just the directory with the class files. The directory structure needs to match the hierarchy.
Also, if you want the JAR
to be executable, you need to include a MANIFEST.MF containing a Main-class
entry specifying which class should be used as the entry point (this class must define a public static void main(String[] args)
).
Netbeans: here is a link to a tutorial.

- 80,905
- 18
- 123
- 145
There are many ways (enough already answered here), but if you want a REALLY SIMPLE way, look at Maven. It just works: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

- 62,186
- 18
- 105
- 157