Eclipse and Maven Packaging Jar

1: add build instructions to pom.xml:

<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.kafka.client.Run</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>	
</plugins>
</build>  

2: in Eclipse, go to package explorer-> Maven -> update project

3: in Eclipse, go to package explorer-> Maven -> run as -> Maven build

4: in the goals, key in "package"

5: Apply and run. The jar will be created with manifest in the target folder

Be the first to comment

Leave a Reply

Your email address will not be published.


*