2012-09-13 20 views
5

wagon-maven-pluginを使用して、自分のWARファイルをサーバーにscpします。それはうまく動作します。私の次のステップは、サーバ上でいくつかのコマンドを実行することです(mkdirなど)。それを手助けするプラグインはありますか? wagon-maven-pluginを使って動作させる方法はありますか?Maven3を使用してssh経由でリモートコマンドを実行

私は比較的新しいmvnです。どんな助けもありがとう。

提案がありますか?

答えて

12

私はexec-maven-pluginでsshコマンドを実行することができました。これは、あらゆる種類のハックを実行し、コマンドを実行するための強力なmavenプラグインです。このソリューションに興味がある人は

<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="https://stackoverflow.com/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> 

希望します。

+0

もう1つのオプションは、wagon-maven-pluginのsshexec機能です – Josh

関連する問題