【问题标题】:bundling multiple artifact for deployment?捆绑多个工件进行部署?
【发布时间】:2015-07-31 00:02:03
【问题描述】:

这是基于answer 的后续行动。

我的结构看起来像

$ ls service/target/
classes             lib             maven-status            surefire-reports
classes.-1194128992.timestamp   maven-archiver          service-1.0-SNAPSHOT.jar

并且其中lib 看起来像

$ ls service/target/lib/
activation-1.1.jar              akka-http-spray-json-experimental_2.11-1.0.jar  mail-1.4.7.jar                  scala-reflect-2.11.2.jar
akka-actor_2.11-2.3.12.jar          akka-parsing-experimental_2.11-1.0.jar      manager-1.0-SNAPSHOT.jar            scala-xml_2.11-1.0.2.jar
akka-http-core-experimental_2.11-1.0.jar    akka-stream-experimental_2.11-1.0.jar       reactive-streams-1.0.0.jar          scalatest_2.11-2.2.5.jar
akka-http-experimental_2.11-1.0.jar     config-1.2.1.jar

作为mvn clean install 的一部分,我想捆绑应该看起来包含的my-deployment-artifact

service-1.0-SNAPSHOT.jar
lib/* (all the jars here)

如何将其创建为 tar.tar.gz 并使用 mvn clean install 生成?

【问题讨论】:

    标签: java scala maven


    【解决方案1】:

    您可以使用maven-assembly-plugin 来完成该任务。

    src/assembly/distribution.xml中创建程序集定义文件

    <assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
        <id>distribution</id>
        <formats>
            <format>tar</format>
        </formats>
        <files>
            <file>
                <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
            </file>
        </files>
        <fileSets>
            <fileSet>
                <directory>${project.build.directory}/lib</directory>
                <outputDirectory>lib</outputDirectory>
            </fileSet>
        </fileSets>
    </assembly>
    

    pom.xml文件中,添加插件声明、执行阶段和目标。

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.5.5</version>
        <configuration>
            <descriptor>${project.basedir}/src/assembly/distribution.xml</descriptor>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    更多格式文件或maven-assembly-plugin的自定义可以在这里找到:https://maven.apache.org/plugins/maven-assembly-plugin/

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 2015-12-04
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      相关资源
      最近更新 更多