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

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

问题描述

我试图上传使用Ant任务的文件。如果我使用Ant直接的文件上传,但如果我呼吁通过Maven的Ant任务(使用 Maven的antrun-插件)我收到以下错误:

这是蚂蚁BuildException已发生:在执行这条线出现以下错误:

  /home/me/proj/build.xml:15:问题:无法创建任务或ftp类型
原因:类org.apache.tools.ant.taskdefs.optional.net.FTP没有被发现。
    这看起来像Ant的可选组件之一。
操作:检查相应的可选JAR中存在
    -ANT_HOME / lib目录

ANT-commonsnet.jar显然是可供Ant:

  $ LS $ ANT_HOME / lib目录| grep的蚂蚁公网
蚂蚁公地net.jar

是Maven的antrun-插件单独定义的类路径蚂蚁,还是我失去了一些东西?


解决方案

  

蚂蚁公地net.jar 显然是可供Ant


是的,但Maven和在 Maven的antrun-插件未使用本地的Ant安装。


  

是单独定义的类路径蚂蚁 Maven的antrun-插件,还是我失去了一些东西?


使用不包含在蚂蚁的默认罐子Ant任务的方式被记录在使用任务不包括在蚂蚁的默认罐子(这绝对应该帮助):


  

要使用不包含在Ant任务
  蚂蚁罐子,就像蚂蚁可选或自定义
  任务您需要添加的依赖
  所需的运行到任务
  插件类路径和使用
   maven.plugin.classpath 引用
如果
  必要的。

 <项目>
  < modelVersion> 4.0.0< / modelVersion>
  < artifactId的>我测试应用< / artifactId的>
  <的groupId>我试验组与LT; /的groupId>
  <&版GT; 1.0-SNAPSHOT< /版本>  <建立>
    <&插件GT;
       <&插件GT;
         <&的groupId GT; org.apache.maven.plugins< /的groupId>
         <&的artifactId GT;的maven-antrun-插件< / artifactId的>
         <&版GT; 1.6 LT; /版本>
         <&执行GT;
           <执行与GT;
             <&ID GT;&FTP LT; / ID>
             &所述;阶段>部署&下; /阶段>
             <结构>
               <目标>                 < FTP行动=发送服务器=为myhostremotedir =/家/测试用户id =X密码=Y取决于=YES详细=YES>
                   <文件集DIR =$ {} project.build.directory>
                     <包括姓名=*罐子。/>
                   < /文件集>
                 < / FTP>                 <的taskdef NAME =myTask类名=com.acme.MyTaskclasspathref =maven.plugin.classpath/>
                 &所述; myTask一个=B/>               < /目标与GT;
             < /结构>
             <目标>
               <&目标GT;运行< /目标>
             < /目标>
           < /执行>
         < /处决>
         <依赖和GT;
           <&依赖性GT;
             <&的groupId GT;公共网< /的groupId>
             <&的artifactId GT;公共网< / artifactId的>
             <&版GT; 1.4.1< /版本>
           < /依赖性>
           <&依赖性GT;
             <&的groupId GT;蚂蚁< /的groupId>
             <&的artifactId GT;蚁公网< / artifactId的>
             <&版GT; 1.6.5< /版本>
           < /依赖性>
           <&依赖性GT;
             <&的groupId GT;蚂蚁< /的groupId>
             <&的artifactId GT;蚂蚁nodeps< / artifactId的>
             <&版GT; 1.6.5< /版本>
           < /依赖性>
         < /依赖和GT;
       < /插件>
    < /插件>
  < /构建>
< /项目>


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 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 is clearly available to Ant:

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

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

解决方案

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

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

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

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

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天全站免登陆