Search code examples
javaautomationperforcemaven-release-plugin

How to set up auto deployment of a maven project on multiple machines?


I have a maven project that lives in 3 servers/hosts.

I was looking at the maven release plugin but I cant seem to find how to push to multiple servers at the same time. BTW my source control is Perforce. I wanted to see if I can deploy the project to multiple locations(servers/hosts) during the mvn package cycle and avoid the manual transfer of the jars to these different machines.

Can somebody point me to some documentation that discusses this?


Solution

  • To achieve this, I created different profiles for each deployment in the POM similar to the following

     <profile>
        <id>deployToDev_Host</id>
            <activation>
                <property>
                    <name>dev</name>
                    <value>test</value>
                </property>
            </activation>
    
            <build>
                <plugins> 
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>restart_service</id>
                                <phase>deploy</phase>
                                <configuration>
                                    <target>
    
                                        <scp trust="yes" file="${project.build.directory}/${project.artifactId}-${project.version}.jar" remoteToFile="location/on/remote/host/" />
                </plugin>
                </plugins>
            </build>                        
        </profile>
    

    Followed this document http://slackspace.de/articles/create-deployment-profiles-with-maven/