Here's how to build a jar with IntelliJ 10 http://blogs.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/
File -> Project Structure -> Project Settings -> Artifacts -> Click green plus sign -> Jar -> From modules with dependencies...
The above sets the "skeleton" to where the jar will be saved to. To actually build and save it do the following:
Extract to the target Jar
OK
Build | Build Artifact | Build
Try Extracting the .jar file from
ProjectName | out | artifacts | ProjectName_jar | ProjectName.jar
This is still an issue in 2017, I hope it will help somebody out there! I found 2 possibilities to create working jar-s under IntelliJ 2017.2
1. Creating artifact from IntelliJ:
You have to change manifest directory:
<project folder>\src\main\java
replace "java" with "resources"
<project folder>\src\main\resources
This is how it should look like:
Then you choose the dependencies what you want to be packed IN your jar, or NEAR your jar file
To build your artifact go to build artifacts and choose "rebuild". It will create an "out" folder with your jar file and its dependencies.
2. Using maven-assembly-plugin
Add build section to the pom file
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>ServiceCreate</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.svt.optimoo.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
This procedure will create the jar file under the "target" folder
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:
For those that benefit from images as I do:
File -> Project Structure
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With