when I package my project with the Maven goal “package”, the resources are included as well. They are originally located in the directory “src/main/resources”.
Because I want to create an executable jar and add the classpath to the manifest, I’m using maven-jar-plugin.
I’ve configured it as the following likes:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>at.program.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Why won’t the jar file created with “jar:jar” include my resources as well. As far as I’m concerned it should use the same directories as the “package” goal (which are in my case inherited from the Maven Super POM).
The
jar:jargoal of the Maven JAR plugin is used to “build a JAR from the current project” and does only one thing: it packages the content oftarget/classesinto a JAR in thetargetdirectory, and that’s all. So, when you runmvn jar:jar, the plugin configuration in your pom is used, butjar:jarwon’t do more things than what I mentioned. Iftarget/classesis empty or doesn’t exist, no classes or resources will be packaged in the resulting JAR.The
packagephase is a build lifecycle phase and when you invokemvn package, all phases beforepackagewill be executed (process-resources,compile,process-test-resources, etc) and will trigger the plugin goals bound to these phases. So, for a project with a<packaging>of typejar,jar:jaris bound topackageand will be run during thepackagephase but prior to that, the goals bound to phases precedingpackagewill be triggered, including the one that copies the resources intotarget/classes.