【问题标题】:How to get the content of a directory inside of WAR that is inside of an EAR that is inside of a ZIP?如何获取 WAR 内部目录的内容,该目录位于 ZIP 内部的 EAR 内部?
【发布时间】:2014-06-20 18:55:37
【问题描述】:

我有以下:

  • WAR1 具有 /images 目录,其中包含:photo1.png、photo2.png
  • WAR2 具有 /images 目录,其中包含:photo2.png、photo3.png
  • WAR3 具有 /images 目录,其中包含:photo4.png、photo5.png
  • EAR1 具有 WAR1WAR2
  • EAR2 具有 WAR3
  • ZIP 文件由 Maven Assembly 插件创建,包含 EAR1EAR2

现在我需要以下内容:

  • 通过 Maven Assembly 插件创建 ZIP 文件时,我需要在 ZIP 文件中创建目录 /images,其中包含 /images 目录的内容ZIPEAR 中的每个 WAR 文件。

如果不清楚,请告诉我,以便我提供更多详细信息。

非常感谢。

【问题讨论】:

    标签: maven zip war ear maven-assembly-plugin


    【解决方案1】:

    第一步是create a separate module like mod-zip,其中包含以下 pom,它依赖于所有工件和 maven-assembly-plugin 的配置。

    您必须适当地将父级更改为您的父级:

      <modelVersion>4.0.0</modelVersion>
    
      <parent>
        <groupId>com.soebes.maven.multiple.artifacts</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.4-SNAPSHOT</version>
      </parent>
    
      <artifactId>mod-zip</artifactId>
      <packaging>pom</packaging>
    
      <name>Mod: ZIP</name>
    
      <dependencies>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>mod-war1</artifactId>
          <version>${project.version}</version>
          <type>war</type>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>mod-war2</artifactId>
          <version>${project.version}</version>
          <type>war</type>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>mod-war3</artifactId>
          <version>${project.version}</version>
          <type>war</type>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>mod-ear1</artifactId>
          <version>${project.version}</version>
          <type>ear</type>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>mod-ear2</artifactId>
          <version>${project.version}</version>
          <type>ear</type>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
              <execution>
                <id>test</id>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <descriptors>
                    <descriptor>test.xml</descriptor>
                  </descriptors>
                </configuration>
              </execution>
            </executions>
          </plugin>
    
        </plugins>
      </build>
    
    
    </project>
    

    其次,您需要一个程序集描述符来描述您想要拥有的东西,这有点棘手:

    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    
      <id>test</id>
      <formats>
        <format>zip</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <dependencySets>
        <dependencySet>
          <unpack>true</unpack>
          <useProjectArtifact>false</useProjectArtifact>
          <includes>
            <include>${project.groupId}:*:war:${project.version}</include>
          </includes>
          <unpackOptions>
            <includes>
              <include>images/**</include>
            </includes>
          </unpackOptions>
        </dependencySet>
      </dependencySets>
      <moduleSets>
        <moduleSet>
          <useAllReactorProjects>true</useAllReactorProjects>
          <includes>
            <include>${project.groupId}:*:ear:${project.version}</include>
          </includes>
          <binaries>
            <outputDirectory>result</outputDirectory>
            <unpack>false</unpack>
          </binaries>
        </moduleSet>
      </moduleSets>
    </assembly>
    

    棘手的事情是通过两个步骤。首先使用dependencySets 和unpackOptions 过滤只有wars 的工件,这将过滤掉其中的图像。其次,您需要通过 moduleSets 来使用 EAR 模块。

    【讨论】:

      猜你喜欢
      • 2014-02-24
      • 1970-01-01
      • 2011-11-26
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2010-10-25
      • 1970-01-01
      • 2011-09-24
      相关资源
      最近更新 更多