简体   繁体   中英

Maven : Not able to copy resources to remote dir

I am using :

  • openjdk version "11.0.1" 2018-10-16
  • Apache Maven 3.6.0 to build my project.

Expecting 3 resource files to be copied from the server from where I am compiling to the server where to copy the resource file.Expected way:

  • Copying context.xml to /online/sand/pps/apache-tomcat-9.0.8/webapps/pps/META-INF from local target/classes/env/${current_env}_context.xml
  • Copying application.properties to /online/sand/pps/apache-tomcat-9.0.8/webapps/pps/WEB-INF/classes from local target/classes/env/${current_env}_application.properties
  • Copying promote_servers.properties to /online/sand/pps/apache-tomcat-9.0.8/webapps/pps/WEB-INF/classes from local target/classes/env/${current_env}_promote_servers.properties

Hence I set up profile in pom.xml as :

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

to copy the resources, I have used :

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

my .war file is being stfp to the right location. However, the resource files are not. I have checked directory permission is right in the remote dir where the files should be copied. Log file for the maven installation says that the resources have been copied to the directories mentioned above and installation is a success.

Any idea on what I am missing? Should I use a different plug-in for resource copy part?

my first guess is that the lifecycle phase of the copying of your file is too late (or just after the sftp of your actual resources) but to prove that you should post also the goal to copy the sftp.

you can try to simply change the

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

to

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

so its in an early stage... see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM