Thursday, August 2, 2012

how to pack a maven jar project with all dependencies and create a executable jar file

first, we need add following plugin into build tag


<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>fully.qualified.MainClass</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
</build>

then do following


mvn assembly:assembly
Note that this way is now deprecated. The preferred way is using:
mvn assembly:single

No comments:

Post a Comment