'Creating a jar from a maven project in intellij
I created a new maven project in IntelliJ and set packaging to jar but when I build it, the target folder does not contain a jar. I'm sure its something really dumb on my part but there are just so many different things i'm reading on different websites and I just feel better asking.
Solution 1:[1]
You should build you project using IDEA's Maven Projects
view.
View -> Tool Windows -> Maven Projects
or open it from left bottom corner menu:
And then build your project with maven goals - i.e. package:
If packaging is set to jar
in pom.xml
, you will get a jar in target
dir.
Solution 2:[2]
Solution 3:[3]
You need the maven jar plugin in order to create a jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>add your main class</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Solution 4:[4]
You need to have "jar" in packaging section of your pom.xml. You can add this before dependencies section:
<packaging>jar</packaging>
Then go to View -> Tool Windows -> Maven and in Maven window expand everything and double click on "package" in Lifecycle section.
Solution 5:[5]
Assuming that the screen-shot shows the complete pom file, you are missing the entries that define the artifact. Try adding something like this following immediately after the tag:
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.example</groupId>
<artifactId>stackoverflow-question</artifactId>
<version>0.0.1-SNAPSHOT</version>
You should end up with stackoverflow-question-0.0.1-SNAPSHOT.jar in your /target directory. You may need to refresh the directory to see it (You certainly have to in Eclipse)
Solution 6:[6]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Amr Lotfy |
Solution 2 | ankit |
Solution 3 | sethu |
Solution 4 | |
Solution 5 | kiwiron |
Solution 6 | Dave Rincon |