I have a project that contains a single module, and some dependencies. I\'d like to create a jar, in a separate directory, that contains the compiled module. In addition, I\
Ant and Maven are widely used. I prefer Ant, I feel it's more lightweight and you the developer are more in control. Some would suggest that's its downside :-)
Here is the official answer of IntelliJ IDEA 2018.3 Help. I tried and It worked.
To build a JAR file from a module;
On the main menu, choose Build | Build Artifact.
From the drop-down list, select the desired artifact of the type JAR. The list shows all the artifacts configured for the current project. To have all the configured artifacts built, choose the Build all artifacts option.
I recently had this problem and think these steps are easy to follow if any prior solution or link is missing detail.
How to create a .jar
using IntelliJ IDEA 14.1.5:
Here are 2 examples with maven project, step by step:
at pom.xml, add maven-jar-plugin.
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>somePackage.sample</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
screen capture: 4. open maven project box by click on the search icon and type maven,
click on clean, then click on install
your jar file will show up inside the target folder
test your jar using java -jar
The MANIFEST.MF needs to be in your resources folder and the Main.Class needs to refer to {package}-{class-name-that-contains-main-class}
As the people above says, but I have to note one point. You have to check the checkbox:
Include in project build
In case you are reading this answer because you are facing "resource file not found" error, try this:
Output Layout
, press Create Archive
to create a new jar, and again, give it a nice name ;)Manifest File
then set correct Main Class
and Class Path
.Add Library Files
, and select libraries you need (you can use Ctrl+A to select all).