Skip to content

Instantly share code, notes, and snippets.

@kumar-de
Last active June 6, 2022 07:59
Show Gist options
  • Save kumar-de/45c6ca8f6ac060f380f5039990ed8745 to your computer and use it in GitHub Desktop.
Save kumar-de/45c6ca8f6ac060f380f5039990ed8745 to your computer and use it in GitHub Desktop.
Create a fat jar using Maven

Create a fat jar using Maven

<?xml version="1.0" encoding="UTF-8"?>
<build>
	<plugins>
        <!-- Set a compiler level -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
        <!-- Maven Assembly Plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <!-- get all project dependencies -->
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <!-- MainClass in mainfest make a executable jar -->
                <archive>
                    <manifest>
                        <mainClass>com.achintya.package.MainApp</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <!-- bind to the packaging phase -->
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment