3

I'm using maven to build my spring boot jar.

With the wagon-maven-plugin i can upload it on my dev server, but then i need to ssh into the server and do the java -jar package.jar command to make the application start. Is there a way with maven to upload the jar AND then run it?

I have tried with men:spring-boot:run but it looks like it only works on local, no upload possibility...

MarioC
  • 2,934
  • 15
  • 59
  • 111
  • If you have Jenkins as guard, you can put this flow into deployment and bounce two steps, but still you need ssh login. – chenrui Jul 18 '17 at 17:20
  • What about heroku? [Deploying Spring Boot Applications to Heroku](https://devcenter.heroku.com/articles/deploying-spring-boot-apps-to-heroku). – K.Nicholas Jul 18 '17 at 19:07
  • Seems to me maven-deploy-plugin will do it ... [Deployment of artifacts in an external SSH command](http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ssh-external.html). Just add args to run a shell script with the ssh command. – K.Nicholas Jul 18 '17 at 19:09
  • Please find the answer in below link [https://stackoverflow.com/questions/909867/maven-copy-local-file-to-remote-server-using-ssh](https://stackoverflow.com/questions/909867/maven-copy-local-file-to-remote-server-using-ssh) – Karthik Tsaliki Jul 19 '17 at 06:16

1 Answers1

1

Add to the pom.xml file (inside of build><plugins>...</plugins></build>) content below and run command: mvn antrun:run@deploy.

                <!-- command: mvn clean package -Pdev; mvn antrun:run@deploy -Pdev -->
                <!-- http://devserver:8081/ -->
                <plugin>
                    <inherited>false</inherited>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.8</version>
                    <executions>
                        <execution>
                            <id>deploy</id>
                            <phase>install</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <target name="scp-deploy" description="Use antrun plugin to deploy with SCP and SSH">
                                    <!-- remote host and the command to be executed there -->

                                    <echo message="Stopping deployed app ..." />
                                    <sshexec trust="true" failonerror="true"
                                        host="${devserver.host}"
                                        username="${devserver.username}"
                                        password="${devserver.password}"
                                        command="stop.sh"
                                        timeout="120000" />

                                    <!-- file to be transferred -->
                                    <echo message="Transfering ${project.build.directory}/${project.build.finalName}.${project.packaging} ..." />
                                    <scp trust="true" failonerror="true" verbose="off" sftp="true" 
                                        file="${project.build.directory}/${project.build.finalName}.${project.packaging}"
                                        todir="${devserver.username}:${devserver.password}@${devserver.host}:${devserver.path}/${project.artifactId}.${project.packaging}" />

                                    <!-- remote host and the command to be executed there -->
                                    <echo message="Starting htct app ..." />
                                    <sshexec trust="true" failonerror="true"
                                        host="${devserver.host}"
                                        username="${devserver.username}"
                                        password="${devserver.password}"
                                        command="start.sh"
                                        timeout="120000" />
                                    <echo message="The deployment is done." />

                                    <taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp">
                                        <classpath refid="maven.plugin.classpath" />
                                    </taskdef>
                                    <taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec">
                                        <classpath refid="maven.plugin.classpath" />
                                    </taskdef>
                                </target>
                            </configuration>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>ant</groupId>
                            <artifactId>ant-commons-net</artifactId>
                            <version>1.6.5</version>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.ant</groupId>
                            <artifactId>ant-jsch</artifactId>
                            <version>1.10.5</version>
                        </dependency>
                    </dependencies>
                </plugin>
Do Tat Hoan
  • 901
  • 9
  • 9