Maven,如何复制文件?

时间:2017-01-14 19:52:32

标签: java maven maven-3 maven-assembly-plugin

我想将一些文件(jar,启动脚本,文档)复制到某个目录,例如项目根目录中的dist/

我正在使用 maven-assembly-plugin 并在pom.xml中设置<configuration><outputDirectory>。它在dist/但在<my_project>-<decsriptor_id>/子目录中创建文件。

有没有办法只在dist/的根目录中输出它?

或者Maven中是否有一个只是复制文件的插件?

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>maven-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <outputDirectory>${project.basedir}/dist</outputDirectory>
                <descriptors>
                    <descriptor>${project.basedir}/src/main/maven-assembly/dist.xml</descriptor>
                </descriptors>
            </configuration>
        </plugin>

dist.xml

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
    <id>dist</id>
    <formats>
        <format>dir</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <files>
        <file>
            <source>path........</source>
            <fileMode>0755</fileMode>
            <outputDirectory>.</outputDirectory>
        </file>
    </files>
</assembly>

1 个答案:

答案 0 :(得分:4)

您可以使用maven-resources-plugin

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.0.2</version>
  <executions>
    <execution>
    <id>copy-resources</id>
    <!-- insert here the phase you need -->
    <phase>validate</phase>
    <goals>
      <goal>copy-resources</goal>
    </goals>
    <configuration>
      <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
      <resources>        
        <resource>
        <directory>src/non-packaged-resources</directory>
        <filtering>true</filtering>
        </resource>
      </resources>          
    </configuration>        
    </execution>
  </executions>
</plugin>