我一直在尝试将打包的 jar 部署到一些通过 maven 以 192.168.0.101 的静态 ip 连接到 lan 的树莓派上。这是我的绒球的重要部分.xml :
<dependencies>
... SNIP ...
<!-- SSH & FTP -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.10.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>scp-to-remote</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Upload jar via ftp to /home/pi/server -->
<scp localFile="${project.basedir}/target/button-masher-1.0.jar"
remoteToFile="${rserver.user}@${rserver.ip}:${rserver.script.server.dir}" verbose="true"
password="${rserver.pass}" trust="true">
</scp>
<!-- calls deploy script -->
<sshexec host="${rserver.ip}" trust="yes"
username="${rserver.user}" password="${rserver.pass}"
command="sh ${rserver.script.server.startup}" />
<taskdef name="scp"
classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp"
classpathref="maven.plugin.classpath" />
<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>
</execution>
</executions>
</plugin>
</plugins>
</build>
这是一张图片,显示 %ANT_HOME%/lib jsch 上.jar 和 jsch-ant.jar 都存在(jsch 是最新版本):ant_home/库
每当我运行 maven install (-Dmaven.test.skip=true) 时,我都会收到此错误:错误
但是所有需要的蚂蚁可选罐子/组件都存在。我使用的IDE是IntelliJ IDEA Ultimate。我使用Windows cmd中的非捆绑(通常安装)maven版本来执行命令。
通过更改修复
maven.plugin.classpath
自
maven.compile.classpath
wagon-maven-plugin 可能是此类事情的正确选择......
您可以在pom文件中进行配置,如下所示:
<project>
[...]
<build>
[...]
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>upload-javadoc</id>
<phase>deploy</phase>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<fromDir>local.dir</fromDir>
<includes>*</include>
<excludes>pom.xml</excludes>
<url>scp://your.remote.host/</url>
<toDir>remote.dir</toDir>
</configuration>
</execution>
</executions>
</plugin>
</build>
[...]
</project>
我建议通过 Docker 镜像或使用 Ansible 之类的东西来配置您的系统来处理这些事情。
增强:
可以使用以下命令执行命令:
<project>
[...]
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>2.8</version>
</extension>
</extensions>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>execute-test-commands</id>
<phase>deploy</phase>
<goals>
<goal>sshexec</goal>
</goals>
<configuration>
<serverId>atlassian-public</serverId>
<url>scp://maven.atlassian.com/public</url>
<commands>
<command>/usr/share/tomcat/bin/tomcat stop</command>
<command>rm -rf /usr/share/tomcat/webapps/ROOT</command>
<command>unzip -o /usr/share/tomcat/webapps/myapp.zip -d /usr/share/tomcat/webapps/</command>
<command>/usr/share/tomcat/bin/tomcat start</command>
</commands>
</configuration>
</execution>
</executions>
</plugin>
</build>
[...]
</project>