Maven 程序集 : copy from specific sub-folder of dependency

标签 maven maven-assembly-plugin

我正在使用 Maven 程序集插件来构建我们产品的 WAR(以前由 Ant 完成)。由于 Apache Ant 有很多遗留物,因此有一个特定要求可以使构建过程更容易:将依赖项的特定子文件夹(例如,jar 或 war 资源)复制到特定的目标子文件夹。

到目前为止,我了解到程序集描述符允许指定 <outputDirectory> ,但是否有机会指定 <sourceDirectory> ?例如,我想将此规则应用于单个 WAR 或 JAR 类型的依赖项。

考虑这个程序集描述符片段示例(不是 100% 准确):

    <dependencySet>
        <unpack>true</unpack>
        <scope>runtime</scope>
        <useProjectArtifact>false</useProjectArtifact>
        <includes>
            <include>my-specific-dependency:war</include>
        </includes>
        <outputDirectory>WEB-INF/myresources</outputDirectory>
    </dependencySet>

我想说我想从 my-specific-dependency:war 复制一些文件夹到 WEB-INF/myresources。

编辑 注意:我知道这不是一个非常正确的要求,因为我们不应该知道 Artifact 内部是什么,正确的方法是声明将整个 Artifact 提取到目标目录(简洁的声明方法)。

最佳答案

您应该能够使用 Maven Dependency 插件来执行此操作,其解包目标是:
http://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>unpack-database-scripts</id>
      <phase>compile</phase>
      <goals>
        <goal>unpack</goal>
      </goals>
      <configuration>
          <artifactItems>
           <artifactItem>
             <groupId>myGroup</groupId>
             <artifactId>myArtifact</artifactId>
             <version>1.0</version>
             <type>war</type>
             <overWrite>true</overWrite>
             <includes>...</includes>
             <outputDirectory>…</outputDirectory>
           </artifactItem>
         </artifactItems>
      </configuration>
    </execution>
  </executions>
</plugin>

关于Maven 程序集 : copy from specific sub-folder of dependency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10278465/

相关文章:

java - Eclipse、QueryDSL 和 Spring Roo 一起工作?

maven-2 - Maven-资源过滤: implications of the @ symbol in resource files

maven - 我希望从我的 jar 中排除一些类文件。我正在使用 maven-assembly-plugin。它仍然添加文件。我没有收到任何错误

maven - 如何在多模块项目中使用 Maven Assembly 插件

java - .zip 项目的 Maven 程序集,仅包含 .jar 和配置文件

Maven 程序集 - 从存档中提取时仅从子文件夹复制文件

java - 使用maven的简单项目需要进行什么阶段?

java - 仅当执行 jar 文件时,REST 客户端中出现 ClientHandlerException

scalatest - 无法扩展由以前版本的 Scala 编译的宏

maven - opencv 构建 github 操作