Creating multiple runnable JAR files from a single Maven project, each including its dependencies, can be achieved by using the Maven Assembly Plugin or the Maven Shade Plugin. These plugins can package your project along with its dependencies into a single JAR (a "fat JAR" or "uber JAR") for each executable part of your project.
Let's assume you have multiple main classes in your project and you want to create a separate runnable JAR for each.
Define the Assembly Descriptors: For each main class, you need to create an assembly descriptor (XML file) that defines how to package that specific part of your project.
<!-- assembly1.xml --> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 https://maven.apache.org/xsd/assembly-1.1.3.xsd"> <id>bundle1</id> <formats> <format>jar</format> </formats> <mainClass>com.example.MainClass1</mainClass> <!-- Add other configurations here --> </assembly>
Repeat this step for each main class, changing the id and mainClass accordingly.
Configure the Maven Assembly Plugin in pom.xml:
Add the plugin to your pom.xml and configure it to use your assembly descriptors.
<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <configuration> <descriptors> <descriptor>src/main/assembly/assembly1.xml</descriptor> <!-- Add other descriptors here --> </descriptors> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Build the Project: Run mvn clean package to create the JAR files.
Alternatively, you can use the Maven Shade Plugin, which provides similar functionality.
Configure the Maven Shade Plugin for Each Main Class:
In your pom.xml, you need to add a configuration for the Shade plugin for each main class.
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.4</version> <executions> <!-- Define an execution for each main class --> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.example.MainClass1</mainClass> </transformer> </transformers> <finalName>jar-name-1</finalName> </configuration> </execution> <!-- Repeat for other main classes --> </executions> </plugin> </plugins> </build>
Build the Project: Just like before, run mvn clean package.
com.example.MainClass1 with the fully qualified name of your actual main class.finalName tag in the Shade plugin configuration determines the name of the output JAR.mybatis ef-code-first asp.net-core-1.1 argmax saga unmarshalling daemons node-mysql bamboo wpf-controls