使用Maven3通过SSH运行远程命令 [英] Run remote command via ssh using Maven3

查看:155
本文介绍了使用Maven3通过SSH运行远程命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using wagon-maven-plugin to scp my WAR file to the server. It works fine. My next step is to perform some commands on the server (mkdir, etc). Is there a plugin that helps me do that? Is there a way to work it out using wagon-maven-plugin?

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

I am relatively new to mvn. Any help would be appreciated.

有什么建议吗?

推荐答案

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

I was able to run ssh commands with exec-maven-plugin. It is a powerful maven plugin to do all sorts of hack and also run commands. For anyone interested in the solution

<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任务,这将很方便.

Another solution I found was to run maven-antrun-plugin. I would not recommend it since it runs ANT tasks and there are a lot of dependencies to it. But its handy if you would need to run ant tasks via maven.

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

希望有帮助!

这篇关于使用Maven3通过SSH运行远程命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆