maven post build copy copy files

时间:2016-06-20 07:12:51

标签: maven openfire maven-antrun-plugin maven-resources-plugin

我目前正在使用特定的项目结构。

准备在目标文件夹中创建WAR的project\WEB-INF\lib内的所有jar文件都应该复制到project\lib

我们是否可以使用maven-antrun或maven-resource插件运行此类脚本,这将在创建实际WAR之前触发?

如果是,那么如何编程呢?不应移动文件,应将其复制。

修改

使用以下xml计算出解决方案并正常工作,这是openfire插件所需的结构

但遗憾的是,只有在第二次执行mvn package

时才会发生这种情况
<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>
  <groupId>com.hpe.sis</groupId>
  <artifactId>TestCopy</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>TestCopy Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core -->
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19.1</version>
    </dependency>

  </dependencies>
  <build>
    <finalName>TestCopy</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.1</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/TestCopy/lib</outputDirectory>
              <resources>
                <resource>
                  <directory>${basedir}/target/TestCopy/WEB-INF/lib</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

1 个答案:

答案 0 :(得分:0)

您可以使用copy-rename-maven-plugin插件:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.coderplus.maven.plugins</groupId>
        <artifactId>copy-rename-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>copy-file</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <sourceFile>src/someDirectory/test.environment.properties</sourceFile>
              <destinationFile>target/someDir/environment.properties</destinationFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

有关更多信息,请参阅:http://coderplus.github.io/copy-rename-maven-plugin/usage.html