通过Maven中的Ant FTP任务上传文件

gno*_*lva 6 ant ftp maven-2 apache-commons-net

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

发生了Ant BuildException:执行此行时发生以下错误:

/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
Run Code Online (Sandbox Code Playgroud)

Ant-commonsnet.jar显然可用于Ant:

$ ls $ANT_HOME/lib | grep ant-commons-net
ant-commons-net.jar
Run Code Online (Sandbox Code Playgroud)

Ant类路径是为maven-antrun-plugin单独定义的,还是我错过了什么?

Pas*_*ent 5

ant-commons-net.jar 很明显Ant可以使用

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

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

使用未包含在Ant的默认jar中的Ant任务的方法记录在使用Ant默认jar中不包含的任务(这应该肯定有帮助):

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

<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>
Run Code Online (Sandbox Code Playgroud)