通过 Maven 中的 Ant FTP 任务上传文件 [英] Upload file via Ant FTP task in Maven

查看:38
本文介绍了通过 Maven 中的 Ant FTP 任务上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Ant 任务上传文件.如果我直接使用 Ant 文件被上传,但如果我通过 Maven 调用 ant 任务(使用 maven-antrun-plugin),我会收到以下错误:

I'm trying to upload a file using an Ant task. If I use Ant directly the file is uploaded, but if I call the ant task via Maven (using the maven-antrun-plugin) I get the following error:

An Ant BuildException has occurred: The following error occurred while execution this line:

An Ant BuildException has occured: The following error occurred while executing this line:

/home/me/proj/build.xml:15: Problem: failed to create task or type ftp
Cause: the class org.apache.tools.ant.taskdefs.optional.net.FTP was not found.
    This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
    -ANT_HOME/lib

ant-commonsnet.jar 显然对 Ant 可用:

ant-commonsnet.jar is clearly available to Ant:

$ ls $ANT_HOME/lib | grep ant-commons-net
ant-commons-net.jar

是否为 maven-antrun-plugin 单独定义了 Ant 类路径,还是我遗漏了什么?

Is the Ant classpath defined separately for maven-antrun-plugin, or am I missing something?

推荐答案

ant-commons-net.jar 显然对 Ant 可用

ant-commons-net.jar is clearly available to Ant

是的,但是 Maven 和 maven-antrun-plugin 没有使用您本地的 Ant 安装.

Yes, but Maven and the maven-antrun-plugin is not using your local Ant install.

是否为 maven-antrun-plugin 单独定义了 Ant 类路径,还是我遗漏了什么?

Is the Ant classpath defined separately for maven-antrun-plugin, or am I missing something?

使用 Ant 的默认 jar 中未包含的任务(这肯定会有所帮助):

The way to use Ant Tasks not included in Ant's default jar is documented in Using tasks not included in Ant's default jar (which should definitely help):

使用未包含在其中的 Ant 任务Ant jar,如 Ant 可选或自定义任务 您需要添加依赖项任务运行所需的插件类路径并使用maven.plugin.classpath 参考 if需要.

To use Ant tasks not included in the Ant jar, like Ant optional or custom tasks you need to add the dependencies needed for the task to run to the plugin classpath and use the maven.plugin.classpath reference if needed.

<project>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>my-test-app</artifactId>
  <groupId>my-test-group</groupId>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-antrun-plugin</artifactId>
         <version>1.6</version>
         <executions>
           <execution>
             <id>ftp</id>
             <phase>deploy</phase>
             <configuration>
               <target>

                 <ftp action="send" server="myhost" remotedir="/home/test" userid="x" password="y" depends="yes" verbose="yes">
                   <fileset dir="${project.build.directory}">
                     <include name="*.jar" />
                   </fileset>
                 </ftp>

                 <taskdef name="myTask" classname="com.acme.MyTask" classpathref="maven.plugin.classpath"/>
                 <myTask a="b"/>

               </target>
             </configuration>
             <goals>
               <goal>run</goal>
             </goals>
           </execution>
         </executions>
         <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-nodeps</artifactId>
             <version>1.6.5</version>
           </dependency>
         </dependencies>
       </plugin>
    </plugins>
  </build>
</project>

这篇关于通过 Maven 中的 Ant FTP 任务上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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