如何在maven-jar-plugin中使用jar:jar目标来构建多个jar文件

时间:2013-10-16 22:07:28

标签: maven maven-plugin maven-jar-plugin

我们的pom.xml在maven-jar-plugin中有多个执行,目的是创建三个独立的jar文件。有什么方法可以调用mvn并构建三个罐子?

目前

mvn compile jar:jar

仍然只创建一个jar。

    <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
    <executions>
        <execution>
            <id>UDFCommon</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
                <forceCreation>true</forceCreation>
                <classifier>UDFCommon</classifier>
                <includes>
                    <include>**/pafcommon/*</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <id>UDFOne</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
                <classifier>UDFOne</classifier>
                <includes>
                    <include>**/dqm/*</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <id>UDFTwo</id>
            <goals><goal>jar</goal></goals>
            <phase>package</phase>
            <configuration>
                <classifier>UDFTwo</classifier>
                <includes>
                    <include>**/ciview/*</include>
                </includes>
            </configuration>
        </execution>
    </executions>
    </plugin>

1 个答案:

答案 0 :(得分:1)

看来jar:jar不能处理多个jar文件。但是运行

mvn compile package

诀窍。

-rw-r--r--   1 steve  staff  2629074 Oct 16 15:24 UDFPafDqm.jar
-rw-r--r--   1 steve  staff    13286 Oct 16 15:24 UDFPafDqm-UDFTwo.jar
-rw-r--r--   1 steve  staff    40315 Oct 16 15:24 UDFPafDqm-UDFOne.jar
-rw-r--r--   1 steve  staff     6942 Oct 16 15:24 UDFPafDqm-UDFCommon.jar

这需要一个assembly.xml:下面显示了一个准分子。

<assembly>
    <id>job</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>${project.build.outputDirectory}</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>


    <dependencySets>
        <dependencySet>
            <scope>runtime</scope>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>