【问题标题】:Maven : Not able to copy resources to remote dirMaven:无法将资源复制到远程目录
【发布时间】:2019-06-20 16:20:50
【问题描述】:

我正在使用:

  • openjdk 版本“11.0.1”2018-10-16
  • Apache Maven 3.6.0 建立我的项目。

期望3个资源文件从我正在编译的服务器复制到要复制资源文件的服务器。预期方式:

  • 将 context.xml 复制到 /online/sand/pps/apache-tomcat-9.0.8/webapps/pps/META-INF 来自本地 目标/类/env/${current_env}_context.xml
  • 将 application.properties 从本地 target/classes/env/${current_env}_application.properties 复制到 /online/sand/pps/apache-tomcat-9.0.8/webapps/pps/WEB-INF/classes
  • 将promote_servers.properties从本地target/classes/env/${current_env}_promote_servers.properties复制到/online/sand/pps/apache-tomcat-9.0.8/webapps/pps/WEB-INF/classes

因此我在 pom.xml 中将配置文件设置为:

<profile>
    <id>dev</id>
    <activation/>
    <properties>
        <INSTALL_MACHINE_LIST>dc1uoappptl01.patamoc-us.com</INSTALL_MACHINE_LIST>
        <COPY_MODE>sftp</COPY_MODE>
        <FTP_USERNAME>theusr</FTP_USERNAME>
        <FTP_PASSWORD>pswd</FTP_PASSWORD>
        <project_lib>/online/sand/pps/apache-tomcat-9.0.8/webapps</project_lib>
    </properties>
</profile>

复制资源,我用过:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <phase>install</phase>
            <configuration>
                <target>
                    <copy file="${project.build.directory}/classes/env/${current_env}_context.xml"
                          tofile="${project_lib}/pps/META-INF/context.xml"
                          overwrite="true"/>
                    <copy file="${project.build.directory}/classes/env/${current_env}_application.properties"
                          tofile="${project_lib}/pps/WEB-INF/classes/application.properties"
                          overwrite="true"/>
                    <copy file="${project.build.directory}/classes/env/${current_env}_promote_servers.properties"
                          tofile="${project_lib}/pps/WEB-INF/classes/promote_servers.properties"
                          overwrite="true"/>
                </target>

            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我的 .war 文件正在 stfp 到正确的位置。但是,资源文件不是。我已检查目录权限是否正确位于应复制文件的远程目录中。 maven安装的日志文件显示资源已经复制到上述目录,安装成功。

知道我缺少什么吗?我应该为资源复制部分使用不同的插件吗?

【问题讨论】:

    标签: java maven maven-antrun-plugin


    【解决方案1】:

    我的第一个猜测是复制文件的生命周期阶段为时已晚(或者就在实际资源的 sftp 之后),但要证明您也应该发布复制 sftp 的目标。

    您可以尝试简单地更改

    <executions>
            <execution>
                <phase>install</phase>
    

    <executions>
            <execution>
                <phase>package</phase>
    

    所以它处于早期阶段...见https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

    【讨论】:

    • 使用的目标:运行
    猜你喜欢
    • 1970-01-01
    • 2017-09-25
    • 2014-06-10
    • 2015-02-25
    • 2013-10-24
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多