One jar with all dependencies

Reading Time: 1 minute

The configuration is below when you issue this command “mvn clean package assembly:single” then you will get a jar file containing all the sources and if  you check the me MANIFEST.MF file and you will see the line “Main-Class: com.tugrulaslan.App” the value we set below in the pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>de.goeuro</groupId>
	<artifactId>GoEuroApp</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>GoEuroApp</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<jdk.version>1.7</jdk.version>
		<maven-compiler.version>3.3</maven-compiler.version>
		<maven-jar-plugin.version>2.6</maven-jar-plugin.version>
		<maven-assembly-plugin.version>2.5.5</maven-assembly-plugin.version>
	</properties>

	<dependencies>
		...
		</dependency>
	</dependencies>
	<build>
		<finalName>${project.artifactId}</finalName>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>${maven-compiler.version}</version>
					<configuration>
						<source>${jdk.version}</source>
						<target>${jdk.version}</target>
					</configuration>
				</plugin>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-assembly-plugin</artifactId>
					<version>${maven-assembly-plugin.version}</version>
					<configuration>
						<finalName>${project.artifactId}</finalName>
						<appendAssemblyId>false</appendAssemblyId>
						<archive>
							<manifest>
								<mainClass>com.tugrulaslan.App</mainClass>
							</manifest>
						</archive>
						<descriptorRefs>
							<descriptorRef>jar-with-dependencies</descriptorRef>
						</descriptorRefs>
					</configuration>
					<executions>
						<execution>
							<phase>package</phase>
							<goals>
								<goal>single</goal>
							</goals>
						</execution>
					</executions>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<version>${maven-jar-plugin.version}</version>
			</plugin>
		</plugins>
	</build>
</project>

Leave a Reply

Your email address will not be published. Required fields are marked *