使用Maven复制文件的最佳做法 [英] Best practices for copying files with Maven

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

问题描述

我有一些配置文件和各种文档,我想使用Maven2将它们从dev环境复制到dev-server目录.奇怪的是,Maven在这项任务上似乎并不强.

I have config files and various documents that I want to copy from the dev environment to the dev-server directory using Maven2. Strangely, Maven does not seem strong at this task.

其中一些选项:

  • 在Maven中简单使用 copy 任务
<copy file="src/main/resources/config.properties" tofile="${project.server.config}/config.properties"/>

  • 使用Ant插件从Ant执行复制.

    • 构造一个类型为 zip 的工件,以及通常为 jar 类型的POM的主要"工件,然后进行拆包将该工件从存储库转移到目标目录.

    • Construct an artifact of type zip, alongside the "main" artifact of the POM which is usually of type jar, then unpack that artifact from the repository into the target directory.

    maven-resources 插件,如下所述.

    Maven Assembly插件-但是,当我想简单且常规地"执行操作时,这似乎需要大量手动定义.

    Maven Assembly plugin -- but this seems to require a lot of manual definitions, when I want to do things simply and "conventionally."

    此页面甚至显示了如何构建插件做复制!

    This page even shows how to build a plugin to do copying!

    maven-upload 插件,如下所述.

    maven-dependency-plugin ,如下所述.


    所有这些似乎都是多余的:Maven应该擅长执行这些标准任务,而不必大惊小怪.


    All these seem needlessly ad hoc: Maven is supposed to excel at doing these standard tasks without fuss and bother.

    有什么建议吗?

    推荐答案

    不要回避Antrun插件.只是因为有些人倾向于认为Ant和Maven是对立的,所以他们不是.如果需要执行一些不可避免的一次性定制,请使用复制任务:

    Don't shy away from the Antrun plugin. Just because some people tend to think that Ant and Maven are in opposition, they are not. Use the copy task if you need to perform some unavoidable one-off customization:

    <project>
      [...]
      <build>
        <plugins>
          [...]
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <phase>deploy</phase>
                <configuration>
                  <tasks>
    
                    <!--
                      Place any Ant task here. You can add anything
                      you can add between <target> and </target> in a
                      build.xml.
                    -->
    
                  </tasks>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      [...]
    </project>
    

    在回答这个问题时,我将重点放在您所问问题的细节上.如何复制文件?这个问题和变量名使我想到了一个更大的问题,例如:是否有更好的方法来处理服务器配置?"使用Maven作为构建系统来生成可部署的工件,然后在单独的模块或完全在其他地方执行这些自定义.如果您共享了更多的构建环境,则可能会有更好的方法-有一些插件可以配置许多服务器.您可以附加在服务器根目录中解压缩的程序集吗?您正在使用什么服务器?

    In answering this question, I'm focusing on the details of what you asked. How do I copy a file? The question and the variable name lead me to a larger questions like: "Is there a better way to deal with server provisioning?" Use Maven as a build system to generate deployable artifact, then perform these customizations either in separate modules or somewhere else entirely. If you shared a bit more of your build environment, there might be a better way - there are plugins to provision a number of servers. Could you attach an assembly that is unpacked in the server's root? What server are you using?

    再次,我敢肯定有更好的方法.

    Again, I'm sure there's a better way.

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

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