I have a java project and i need to create jar file from my project . any body can tell me what is the simplest way to make this?
-
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html – Konstantin Yovkov Jul 08 '14 at 09:34
-
2With Eclipse : Export > JAR – Michael Laffargue Jul 08 '14 at 09:34
-
Use an IDE they all will create executable jars. – PeterMmm Jul 08 '14 at 09:34
-
1Don't use an IDE to understand the jar mechanism in deep. – PeterMmm Jul 08 '14 at 09:36
-
i use intellij IDE 13. – Abbas Rahimi Jul 08 '14 at 09:36
-
If you are using eclipse, read this: http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-33.htm – Siddharth M Jul 08 '14 at 09:38
-
What do you expect from the Jar? Is the purpose a library or an executable jar or something else? – Jeroen Jul 08 '14 at 09:38
-
can i create jar file with using cmd code? – Abbas Rahimi Jul 08 '14 at 09:39
-
1@Dinamit92 : if you don't know how to create a jar file, you shouldn't be using an IDE – Stultuske Jul 08 '14 at 09:43
-
6@Jayaprasad : I live in IRAN and google is limited here! – Abbas Rahimi Jul 08 '14 at 09:48
5 Answers
From scratch.. with CMD
The command line is what almost every other application will use to build your JAR
file. They just wrap it up a little nicer for you. In truth, it's very simple to do yourself. Obviously Java have explained this way in detail so there is no sense in me repeating it.
Note: You need to have your JDK/bin directoy appended onto your %PATH%
system variable to be able to use this method.
Double Note: As pointed out in the comments, I'd suggest you keep trying this method until you understand it. It is very important that you get these things at a low level, so if something goes wrong with the IDE, you have a much better understanding of how to solve it.
Eclipse
Eclipse offers a nice interface for it. You can find a step by step tutorial here. The long and short of it is..
Right click on Project -> Export -> JAR File -> Select the Java files to include
When you've done this, hit finish
and you're golden. The tutorial also adds some additional tips in to make it as seamless as possible.
IntelliJ IDEA
My personal favourite IDE. This question offers a nice explanation for how to export as a JAR file. Again, the long and short of it..
File -> Project Structure -> Artifacts
In there, you can then create a new artifact by clicking the +
icon. This will give you an option for the file type, which is .JAR
and which modules you want to include in your artifact. When you're done, you go to..
Build -> Build Artifacts
And it will create the JAR
file from your project.
Using Maven
I've often found this to be a pretty awesome tool, and definitely one worth considering. In IntelliJ, by double clicking the install
procedure in the life cycles..
This will create a new JAR
file in your .target
directory.
Note: Some IDEs (like IntelliJ) will hide the .target
directory by default. Make sure you make it visible in the project settings.

- 26,815
- 5
- 55
- 89
-
Using the 'package' is enough to create the jar. The 'install' goal is used to store it inside your local maven repository. – Jeroen Jul 08 '14 at 13:47
The basic format of the command for creating a JAR file is:
jar cf jar-file input-file(s)
The options and arguments used in this command are:
- The c option indicates that you want to create a JAR file.
The f option indicates that you want the output to go to a file rather than to stdout.
jar-file is the name that you want the resulting JAR file to have. You can use any filename for a JAR file. By convention, JAR filenames are given a .jar extension, though this is not required.
The input-file(s) argument is a space-separated list of one or more files that you want to include in your JAR file. The input-file(s) argument can contain the wildcard * symbol. If any of the "input-files" are directories, the contents of those directories are added to the JAR archive recursively.
The c and f options can appear in either order, but there must not be any space between them.

- 3,642
- 3
- 33
- 55
A JAR file is nothing but a ZIP file with added meta-information for the Java Runtime Environment. So the easiest way is to actually zip your classes files including that META-INF folder by hand, then rename the file to JAR. How you get your classes files however is a different story.
The easiest practical way is to hit the build button in your IDE, which will then compile your code into class files, create an appropriate set of meta information and then conveniently zips the whole thing into a JAR file.

- 13,879
- 6
- 30
- 54
Asking for a maven solution, you would need to specify a single pom.xml
in your project
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>you.specify.something.preferably.a.domain.name</groupId>
<artifactId>name-of-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>
And with this you can do a
mvn package
To build the project. However, it relies on a lot of defaults, you would probably want to differ.

- 4,777
- 1
- 21
- 44