Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven—在远程服务器上部署一个Spring引导jar文件并运行它_Maven_Spring Boot - Fatal编程技术网

Maven—在远程服务器上部署一个Spring引导jar文件并运行它

Maven—在远程服务器上部署一个Spring引导jar文件并运行它,maven,spring-boot,Maven,Spring Boot,我正在使用maven构建我的spring boot jar 使用VangMaven插件,我可以将其上传到我的开发服务器上,但是接下来我需要使用ssh将其上传到服务器上,并执行java-jar package.jar命令来启动应用程序。maven有没有办法上传jar然后运行它 我试过使用men:spring boot:run,但它似乎只在本地运行,没有上传的可能性…添加到pom.xml文件(在build>的内部…)下面的内容并运行命令:mvn antrun:run@deploy

我正在使用maven构建我的spring boot jar

使用VangMaven插件,我可以将其上传到我的开发服务器上,但是接下来我需要使用ssh将其上传到服务器上,并执行java-jar package.jar命令来启动应用程序。maven有没有办法上传jar然后运行它

我试过使用men:spring boot:run,但它似乎只在本地运行,没有上传的可能性…

添加到pom.xml文件(在
build>的内部…
)下面的内容并运行命令:
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>

假的
org.apache.maven.plugins
maven antrun插件
1.8
部署
安装
跑
蚂蚁
蚂蚁公地网
1.6.5
org.apache.ant
ant jsch
1.10.5

如果您让Jenkins担任警卫,您可以将此流程放入部署并跳出两个步骤,但仍然需要ssh登录。heroku呢。在我看来,maven部署插件可以做到这一点。只需添加args即可使用ssh命令运行shell脚本。请在下面的链接中找到答案