Maven: Packaging all dependencies in a single JAR


Add maven-assembly-plugin to your pom.xml and bind it to the package lifecycle event. mvn clean package will do the trick.


<project>

	[...]

	<build>

		<plugins>

			<plugin>

				<artifactId>maven-jar-plugin</artifactId>

				<configuration>

					<archive>

						<manifest>

							<mainClass>fully.qualified.MainClass

							</mainClass>

						</manifest>

					</archive>

				</configuration>

			</plugin>

			<plugin>

				<artifactId>maven-assembly-plugin</artifactId>

				<configuration>

					<descriptorRefs>

						<descriptorRef>jar-with-dependencies

						</descriptorRef>

					</descriptorRefs>

				</configuration>

				<executions>

					<execution>

						<id>make-my-jar-with-dependencies</id>

						<phase>package</phase>

						<goals>

							<goal>single</goal>

						</goals>

					</execution>

				</executions>

			</plugin>

			[...]

		</plugins>

		[...]

	</build>

</project>

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 26 other followers

%d bloggers like this: