如何在maven中的单个jar中添加所有依赖项,然后应用程序集插件?

时间:2013-06-10 14:37:00

标签: maven-2 packaging maven-assembly-plugin

我的项目有一个父模块,它有3个子模块。我正在尝试使用maven程序集插件创建一个胖罐。但是,我想要的是创建一个胖jar然后应用assembly.xml文件来进一步捆绑我的项目。

module1 pom.xml

<dependencies>
    <dependency>
        <groupId>common</groupId>
        <artifactId>commonutils</artifactId>
        <version>1.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <descriptor>src/main/assembly/oozie.xml</descriptor>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我的汇编文件

<assembly>
<id>bundle</id>
<formats>
    <format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<baseDirectory>search</baseDirectory>

<fileSets>
    <fileSet>
        <directory>${project.basedir}/src/main/workflow</directory>
        <outputDirectory>/</outputDirectory>
        <excludes>
            <exclude>*/**.properties</exclude>
        </excludes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}</directory>
        <outputDirectory>/lib</outputDirectory>
        <includes>
            <include>*.jar</include>
        </includes>
    </fileSet>
</fileSets>

<files>
    <file>
        <source>${project.basedir}/src/main/workflow/job.properties</source>
        <outputDirectory>/</outputDirectory>
        <filtered>true</filtered>
    </file>
</files>

<moduleSets>
    <moduleSet>
        <useAllReactorProjects>true</useAllReactorProjects>
        <binaries>
            <outputDirectory>/</outputDirectory>
            <unpack>false</unpack>
            <dependencySets>
                <dependencySet>
                    <outputDirectory>lib</outputDirectory>
                    <unpack>false</unpack>
                    <scope>runtime</scope>
                </dependencySet>
            </dependencySets>
        </binaries>
    </moduleSet>
</moduleSets>

运行

mvn package

最终jar只包含模块代码而不是所有依赖项? 这里有什么问题?

1 个答案:

答案 0 :(得分:2)

使用完全符合此目的的预定义汇编描述符jar-with-dependencies