Add these lines in pom.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
We use Maven Assembly plugin here. We can include the 'single' goal from maven-assembly-plugin into the 'package' phase. So rather than typing 'mvn assembly:assembly', we can just type 'mvn package' and all the dependencies will be inside a single JAR.
To build an executable JAR, we need an additional step to include the Main-Class in the MANIFEST.MF. All we need to do is to add these lines in the pom.xml as shown below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<archive>
<manifest>
<mainClass>myproject.Main</mainClass>
</manifest>
</archive>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
No comments:
Post a Comment