Maven,如何复制文件? [英] Maven, how to copy files?

查看:200
本文介绍了Maven,如何复制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to copy some files (jar, launch scripts, docs) to some directory, like dist/ in project root.

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

I am using maven-assembly-plugin and set <configuration><outputDirectory> in pom.xml. It creates files in dist/ but inside <my_project>-<decsriptor_id>/ subdirectory.

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

Is there any way to output it just in the root of dist/?

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

Or is there a plugin in Maven that simply copies files?

        <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>


推荐答案

您可以使用 maven-resources-plugin

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.0.2</version>
  <executions>
    <execution>
    <id>copy-resources</id>
    <!-- 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>

这篇关于Maven,如何复制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆