top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to build fat jar with maven?

+2 votes
101 views
How to build fat jar with maven?
posted Oct 1, 2014 by Amit Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Add following plugin to your pom.xml

    </configuration>
    <executions>
        <execution>
            <id>assemble-all</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>
</plugins>
</build>

After configuring this plug-in, running mvn package will produce two jars: one containing just the project classes, and a second fat jar with all dependencies with the suffix "-jar-with-dependencies".

if you want correct classpath setup at runtime then also add following plugin

   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>fully.qualified.MainClass</mainClass>
                </manifest>
            </archive>
        </configuration>
    </plugin>
answer Oct 3, 2014 by Kali Mishra
Similar Questions
+2 votes

Ivy offers the possibility to access maven repositories and download artifacts from there. There are only pom files in those repositories and no ivy.xml.

They can be retrieved with an ivy resolver that runs in m2compatible mode.

<ibiblio name="maven2" m2compatible="true"/>

Especially for this Use-case I want to know:

  1. which scopes are available by default and what artifacts will they offer
  2. How is a maven scoped mapped to an ivy conf / configuration?
+3 votes

I want to write a Makefile that compiles. My question here is how to add an external library using Make syntax?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...