2012-09-13 9 views
5

Używam wtyczki-wagonu do scp pliku WAR na serwerze. To działa dobrze. Następnym krokiem jest wykonanie niektórych poleceń na serwerze (mkdir itp.). Czy istnieje wtyczka, która pomaga mi to zrobić? Czy istnieje sposób na to, aby go wypróbować za pomocą wtyczki wagon-maven?Uruchom komendę zdalną przez ssh, używając Maven3

Jestem względnie nowy w firmie mvn. Każda pomoc będzie doceniona.

Wszelkie sugestie?

Odpowiedz

12

Udało mi się uruchomić polecenia ssh z exec-maven-plugin. Jest to potężna wtyczka maven do robienia wszelkiego rodzaju hackowania, a także uruchamiania poleceń. Dla wszystkich zainteresowanych w roztworze

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

Innym rozwiązaniem znalazłem uruchomić maven-antrun-plugin. Nie polecałbym go, ponieważ uruchamia on zadania ANT i istnieje wiele zależności od niego. Ale jest to przydatne, jeśli musisz wykonywać zadania mrówek za pomocą 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="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> 

Mam nadzieję, że pomoże!

+0

Inną opcją jest funkcja sshexec z wtyczką wagon-maven-plugin – Josh

Powiązane problemy