使用maven程序集插件创建包含胖jar的ZIP文件(jar-with-dependencies)

时间:2016-01-18 10:26:34

标签: java maven jar maven-assembly-plugin

我正在使用maven assembly-plugin,我想创建一个ZIP文件,其中包含一个胖jar(jar-with-dependencies)。我无法使用mvn package在一次运行中创建此项。我可以取消注释descriptor的配置或取消注释jar-with-dependencies部分。

build的{​​{1}}部分如下:

pom.xml

<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>src/main/assembly/dist.xml</descriptor> </descriptors> <finalName>sample-documentum-downloader</finalName> </configuration> <executions> <execution> <id>jar-with-dependencies</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <finalName>${project.artifactId}</finalName> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>com.foo.DownloadDocuments</mainClass> </manifest> </archive> </configuration> </execution> <execution> <id>assemble-all</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> 是:

dist.xml

我如何重组以在一次运行中创建包含远JAR的ZIP。

感谢您的支持。

2 个答案:

答案 0 :(得分:2)

感谢Tunaki,我的build部分现在看起来像这样:

  <build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <finalName>${project.artifactId}</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <mainClass>com.foo.DownloadDocuments</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>

                <execution>
                    <id>assemble-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>src/main/assembly/dist.xml</descriptor>
                        </descriptors>
                        <finalName>sample-documentum-downloader</finalName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>

答案 1 :(得分:1)

问题在于您将(function() { // define and subscribe here })(); 元素声明为插件的全局元素。这意味着所有执行都将继承该配置:<configuration>,但assemble-all。因此,继承的jar-with-dependencies可能会弄乱<descriptors>

您需要将<descriptorRefs>元素移动到特定的<configuration>执行,就像执行assemble-all一样。