来自一个 maven 项目的多个程序集
2022-09-01 06:14:07
我们有不同的java源代码“项目”。3个项目是完全相同的(胖客户端,相同的依赖项等) - 只有另一个主类必须调用。
今天,我们有一个带有主类的基础项目:
<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>