【问题标题】:How to add all dependencies in single jar in maven and then apply assembly plugin?如何在 maven 的单个 jar 中添加所有依赖项,然后应用程序集插件?
【发布时间】:2013-06-06 06:13:36
【问题描述】:

我的项目有一个父模块,其中有 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 只包含模块代码而不是它的所有依赖项? 这里有什么问题??

【问题讨论】:

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


    【解决方案1】:

    使用完全满足此目的的预定义程序集描述符jar-with-dependencies

    【讨论】:

    • 小心组装插件中的错误,尤其是在使用 Spring 时。我使用了 Shade 插件,效果更好。
    • maven-assembly-plugin 有哪些 bug?与Spring的关系在哪里?除此之外,基于问题的时间,许多新版本的 maven-assembly-plugin 已经发布。
    • 在这里描述并在上周由我体验过:mgorski.net/2013/dev/…
    猜你喜欢
    • 2016-05-14
    • 1970-01-01
    • 2014-04-25
    • 2011-09-06
    • 2015-10-22
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 2016-05-16
    相关资源
    最近更新 更多