maven - 使用 Maven 通过 SFTP 传输 Artifact

标签 maven tomcat ant sftp

我正在尝试将构建任务添加到 Maven pom 文件中,以便我可以将 jar 文件和一些 xml 文件传输到 SFTP 服务器(它是安装了 Tomcat 的虚拟机),但我一直无法这样做远。

我查看了一些链接,但它们要么不太符合要求,要么缺少步骤,要么不起作用。我基本上是 Maven 的初学者,所以我不确定我是否做对了。

要求是我想调用 Maven 构建,使用主机名、用户名和密码(我正在使用)的命令行参数,然后将 jar 文件和 xml 文件上传到运行 Tomcat 的 VM通过 SFTP 在其中(FTP 不起作用,而且我认为 SCP 不会起作用,因为我没有密码文件)。我也不想弄乱主要的 Maven settings.xml 文件来添加连接细节,我发现的一些链接似乎依赖于它。

到目前为止,我有以下配置文件,使用 FTP,但由于没有使用 SFTP,它不起作用。

<profiles>
    <profile>
        <!-- maven antrun:run -Pdeploy -->
        <id>deploy</id>
        <build>
            <plugins>
                <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-url}"
                                remotedir="/usr/share/myappserver/webapps/myapp/WEB-INF/lib"
                                userid="${user-id}" password="${user-password}" depends="no"
                                verbose="yes" binary="yes">
                                <fileset dir="target">
                                    <include name="artifact.jar" />
                                </fileset>
                            </ftp>

                            <ftp action="send" server="${server-url}"
                                remotedir="/var/lib/myappserver/myapp/spring"
                                userid="${user-id}" password="${user-password}" depends="no"
                                verbose="yes" binary="yes">
                                <fileset dir="src/main/resource/spring">
                                    <include name="*.xml" />
                                </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>
            </plugins>
        </build>
    </profile>
</profiles>

我尝试将 ftp 换成 sftp,并改用 org.apache.tools.ant.taskdefs.optional.ssh.SFTP,但它似乎不起作用。

总而言之,SFTP 配置需要尽可能多地包含在 pom 文件中,并在调用时传入主机 url、用户名和密码等内容。

最佳答案

我会使用 Wagon Maven plugin其目标是 upload-singleupload 而不是 antrun:

  • wagon:upload-single uploads the specified file to a remote location.

  • wagon:upload uploads the specified set of files to a remote location.

关于maven - 使用 Maven 通过 SFTP 传输 Artifact ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32526401/

相关文章:

java - 如何修改使用 cxf-codegen 插件创建的生成文件然后进行编译?

reactjs - tomcat apache 8 服务器上的 Pentaho API(端口 - 8080)在通过不同的 Web 应用程序(react JS,端口 - 3000)调用时会出现 COR 问题

tomcat - servlet 中的 JOptionPane 不适用于 tomcat

ant - 如何为要在 jboss 5.1 中部署的基于 EJB 3.0 的代码创建单元测试?

eclipse - Eclipse 中不可解析的父 POM

java - 使用properties-maven-plugin选择application.properties

java - Eclipse 插件自动获取

tomcat - 如何告诉用户,该应用程序已从服务器中删除?

Ant 贡献 : equals doesn't work in for loop

ant - 如何检测安装的 tomcat 版本并使用 Ant Apache 脚本设置 CATALINA_HOME env 变量?