【问题标题】:how to create a zip file using maven which has multiple projects如何使用具有多个项目的maven创建一个zip文件
【发布时间】:2012-08-01 12:47:07
【问题描述】:

我有 3 个模块链接到一个父项目。我需要创建一个包含所有这些项目的 zip 文件。我知道可以使用 Maven 程序集插件来完成。但是我应该在哪个 pom.xml 中使用它。有没有办法可以将 3 个项目中的资源复制到 1 个公共文件夹中。有没有相同的例子。这是一个多模块构建

【问题讨论】:

  • 我假设您的意思是“链接到父项目”,这是您的其他模块的父 pom,称为多模块构建?

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


【解决方案1】:

为此,最好的方法是在您的多模块构建中创建一个单独的模块,从而形成以下结构:

 root (pom.xml)
   +--- mod1 (pom.xml)
   +--- mod2 (pom.xml)
   +--- mod3 (pom.xml)
   +--- mod-package (pom.xml)

mod-package 的 pom.xml 是这样的:

<project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.soebes.packaging.test</groupId>
    <artifactId>root</artifactId>
    <version>0.1.0-SNAPSHOT</version>
  </parent>

  <artifactId>mod-package</artifactId>
  <packaging>pom</packaging>

  <name>Packaging :: Mod Package</name>

 <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <descriptors>
            <descriptor>pack.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>package-the-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

不要忘记位于 mod-package/pack.xml 中的 pack.xml 文件:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <id>pack</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <!-- Enable access to all projects in the current multimodule build! -->
      <useAllReactorProjects>true</useAllReactorProjects>
      <binaries>
        <outputDirectory>modules/${artifactId}</outputDirectory>
        <unpack>false</unpack>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

【讨论】:

  • 我应该进行哪些更改以确保将文件复制到上述文件夹中
  • 您具体说的是哪个文件夹以及哪些文件?
  • 我在 mod1 的 config 文件夹中有一些配置文件。我在 mod2 的 config 文件夹中有其他配置文件。我想将所有这些配置文件放在 zip 文件中的一个公共文件夹中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-18
  • 1970-01-01
  • 2012-05-26
  • 2011-11-10
  • 2016-09-12
相关资源
最近更新 更多