将多个模块罐组合成一个

时间:2018-08-07 03:10:10

标签: java maven

现在我有一个Maven项目,这是我的项目结构:

| sound(parent)
| -- sound-service (sub-module)
| -- sound-start (sub-module)

sound的{​​{1}}中。我有以下内容:

pom

依次单击“清理-编译-软件包”,IDEA IntelliJ帮助我为每个子模块创建两个JAR软件包。但是我想要的是一个包含所有依赖项和JAR库的单个JAR文件。我还在父根的pom文件中添加了以下maven插件,但整个过程仍然无法获得一个JAR。

<modules>
    <module>sound-service</module>
    <module>sound-start</module>
</modules>

我错过了什么吗?我还需要在<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>com.yct.Application</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> 的{​​{1}}中添加一些其他依赖项吗?

2 个答案:

答案 0 :(得分:0)

jar-with-dependencies可以帮助您构建具有依赖项而不是模块 jar

请尝试使用<modules></modules>,而不要使用<dependencies></dependencies>

答案 1 :(得分:0)

我认为在Maven中将单罐应用程序组合在一起的推荐方法是使用shade插件。在我的一个项目中,我将其配置如下:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <configuration>
            <!-- see http://maven.apache.org/plugins/maven-shade-plugin/examples/attached-artifact.html -->
            <shadedArtifactAttached>true</shadedArtifactAttached>
            <shadedClassifierName>standalone</shadedClassifierName>
            <transformers>
                <transformer
                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                    <mainClass>main.class.name.here</mainClass>
                </transformer>
                <transformer
                    implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer" />
                <transformer
                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                    <resource>META-INF/spring.handlers</resource>
                </transformer>
                <transformer
                    implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                    <resource>META-INF/spring.factories</resource>
                </transformer>
                <transformer
                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                    <resource>META-INF/spring.schemas</resource>
                </transformer>
                <transformer
                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
            </transformers>
        </configuration>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>com.github.edwgiz</groupId>
                <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
                <version>2.8.1</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.2.5.RELEASE</version>
            </dependency>
        </dependencies>
    </plugin>