Creating Two Executable Jars Using maven-assembly-plugin

前端 未结 1 1550
夕颜
夕颜 2021-01-25 10:34

I have a Maven project and I want to create two executable jar files from it. One will be used interactively by users and a second will be run as a scheduled job that reads the

相关标签:
1条回答
  • 2021-01-25 10:51

    So as soon as I posted this, I found this thread:

    Create multiple runnable Jars (with depencies included) from a single Maven project

    This uses a different approach in that it doesn't use two profiles, it uses two executions, as such:

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <executions>
            <execution>
                <id>build-publisher</id>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <archive>
                        <manifest>
                            <mainClass>fully.qualified.path.Publisher</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <finalName>${project.artifactId}</finalName>
                </configuration>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
            <execution>
                <id>build-logReader</id>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <archive>
                        <manifest>
                            <mainClass>fully.qualified.path.LogReader</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <finalName>${project.artifactId}-logReader</finalName>
                </configuration>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    This seems to be working. The moral of the story seems to be that I don't completely understand profiles or when they should be used.

    0 讨论(0)
提交回复
热议问题