How to create jar file from Maven project in eclipse

I have a Maven project, but I am not familiar with Maven. I just wanted to create an executable JAR file from this Maven project to use it in another eclipse project. I appreciate any help.

+5
source share
4 answers

To create a jar from Eclipse, right-click the name of your maven project, then

Run as> Maven install

+9
source

Command Line Approach:

At the root of the project (maven project) should be pom.xml. Go to this root and run the mvn package. If this is correct, there should be a new folder named target in the project root directory. There must be a jar file inside this folder.

+2
source

First of all, you should be aware of security in Java. Many jars will not work in fatjars if they are included in other projects (e.g. bouncycastle).

If you make a simple executable jar that does not have libs, and all of them are required on the way to the classes, the default assembly (when the packageing tag is set to jar) will be fine and you just need the appropriate manifest.

If you need all the libraries inside (fatjar), you need to configure it yourself.

There are several plugins for it, for example maven-shade-plugin :

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.3</version> <configuration> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.RSA</exclude> <exclude>META-INF/*.INF</exclude> </excludes> </filter> </filters> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <manifestEntries> <Main-Class>my.package.MainClass</Main-Class> <Class-Path>.</Class-Path> </manifestEntries> </transformer> </transformers> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>fat</shadedClassifierName> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> 
+2
source

Right click maven project,

select Run As-> Maven Build ....

Enter the package in the Goals field.

Click Run.

Refer: https://teck4world.blogspot.com/2017/10/creating-jar-deployment-package-using.html

0
source

All Articles