Two ways to create jar file in IntelliJ
- Creating artifact from IntelliJ
- Using maven-assembly-plugin
Creating artifact from IntelliJ:
• Go to project structure:
• Create a new artifact:
• Select the main class, and be sure to change the manifest folder:
You have to change manifest directory:
\src\main\java
replace “java” with “resources”
\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. Check include in project build
• To build your artifact go to build artifacts and choose “rebuild”. It will create an “out” folder with your jar file and its dependencies.
• Click build
• This procedure will create the jar file under the “out” folder
- 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>
Note : Change the highlighted [art with your packageName.ClassName
• Create a new run/debug configuration:
• Choose application:
• Fill in the form
• Add the “assembly:single” maven goal after build to be executed last
• Save it, then run
This procedure will create the jar file under the “target” folder