我们有不同的java源代码“项目”。3 个项目完全相同(fatclient、相同的依赖项等)——只有另一个主类需要调用。
今天我们有一个带有主类的基础项目:
<project>
<groupId>net.company.BaseTool</groupId>
<artifactId>BaseTool</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BaseTool</name>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>net.company.BaseTool</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
和其他依赖于基础项目的项目
<project>
<groupId>net.company.AnotherTool</groupId>
<artifactId>AnotherTool</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AnotherTool</name>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>net.company.AnotherTool</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.company.BaseTool</groupId>
<artifactId>BaseTool</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
我们这样做是因为我们需要简单的双击可启动应用程序。
但我不想为每个应用程序创建一个额外的 java 项目。
我的问题是:是否可以从一个项目创建多个程序集?如果是,应该怎么做。
解决方案来了
<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>my.company.toolbox</groupId>
<artifactId>toolbox</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>toolbox</name>
<url>http://wiki.company.my/toolbox</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<finalName>toolbox</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>ToolOne</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>ToolOne</finalName>
<archive>
<manifest>
<mainClass>my.company.ToolOne</mainClass>
</manifest>
</archive>
</configuration>
</execution>
<execution>
<id>ToolTwo</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>ToolTwo</finalName>
<archive>
<manifest>
<mainClass>my.company.ToolTwo</mainClass>
</manifest>
</archive>
</configuration>
</execution>
<execution>
<id>ToolThree</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>ToolThree</finalName>
<archive>
<manifest>
<mainClass>my.company.ToolThree</mainClass>
</manifest>
</archive>
</configuration>
</execution>
<execution>
<id>ToolFour</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>ToolFour</finalName>
<archive>
<manifest>
<mainClass>my.company.ToolFour</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>