gpt4 book ai didi

maven-3 - 使用 Maven3 通过 ssh 运行远程命令

转载 作者:行者123 更新时间:2023-12-04 10:27:15 26 4
gpt4 key购买 nike

我正在使用 wagon-maven-plugin 将我的 WAR 文件发送到服务器。它工作正常。我的下一步是在服务器上执行一些命令(mkdir 等)。有没有插件可以帮助我做到这一点?有没有办法使用 wagon-maven-plugin 解决这个问题?

我对 mvn 比较陌生。任何帮助,将不胜感激。

有什么建议么?

最佳答案

我能够使用 exec-maven-plugin 运行 ssh 命令。它是一个强大的 Maven 插件,可以执行各种 hack 并运行命令。对于任何对解决方案感兴趣的人

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>sh</executable>
<arguments>
<!-- Shell script location -->
<argument>runscript.sh</argument>
<!-- arg #1 -->
<argument>${file_1}</argument>
</arguments>
</configuration>
</plugin>

我发现的另一个解决方案是运行 maven-antrun-plugin。我不会推荐它,因为它运行 ANT 任务并且有很多依赖项。但如果您需要通过 Maven 运行 ant 任务,它会很方便。

<plugin>
<inherited>false</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<configuration>
<target>
<loadproperties srcFile="deploy.properties" />
<ftp action="send" server="server"
remotedir="/a/b" userid="usr"
password="pw" depends="no"
verbose="yes" binary="yes">
<fileset dir="modules/my-module/target">
<include name="file.zip" />
</fileset>
</ftp>

<!-- calls deploy script -->
<sshexec host="host" trust="yes"
username="usr" password="pw"
command="sh /my/script.sh" />

<!-- SSH -->
<taskdef name="sshexec"
classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
classpathref="maven.plugin.classpath" />
<taskdef name="ftp"
classname="org.apache.tools.ant.taskdefs.optional.net.FTP"
classpathref="maven.plugin.classpath" />
</target>
</configuration>
...
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>jsch</groupId>
<artifactId>jsch</artifactId>
<version>0.1.29</version>
</dependency>
</dependencies>
</plugin>

希望有帮助!

关于maven-3 - 使用 Maven3 通过 ssh 运行远程命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12412519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com