来自一个maven项目的多个程序集 [英] Multiple assemblies from one maven project

查看:76
本文介绍了来自一个maven项目的多个程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有不同的java源代码项目。 3个项目是完全相同的(fatclient,相同的依赖项等) - 只有另一个主类必须被调用。

we have different java source code "projects". 3 projects are completly identical(fatclient, same dependencies etc.) - there is only another main class that have to be invoked.

今天我们有一个基础项目主要类别:

Today we have one base-project with a main class:

<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>

以及其他依赖基础项目的项目

and other projects that depending on the base-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>

我们这样做,因为我们需要简单的双击可启动应用程序。

We are doing this, because we need simple double-click startable applications.

但我不想为每个应用程序创建一个额外的java项目。

But I dont want to create an extra java project for each application.

我的问题是:是否可以从一个项目创建多个程序集?如果是,则应该如何完成。

My question is: Is it possible to create multiple assemblies from one project? And if yes, how it should be done.

解决方案

<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>


推荐答案

你可以使用不同的执行然后将生成的程序集附加到构建中。当然,您必须为程序集插件配置中的工件配置不同的最终名称。

You can use different executions of the assembly plugin and then attach the resulting assembly to the build. Of course you have to configure different final names for the artifacts in the assembly plugin configuration.

这篇关于来自一个maven项目的多个程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆