在Maven中通过Ant FTP任务上传文件
我正在尝试使用Ant任务上载文件。如果我直接使用Ant,文件会被上传,但是如果我通过Maven调用Ant任务(使用在Maven中通过Ant FTP任务上传文件,ant,maven-2,ftp,apache-commons-net,Ant,Maven 2,Ftp,Apache Commons Net,我正在尝试使用Ant任务上载文件。如果我直接使用Ant,文件会被上传,但是如果我通过Maven调用Ant任务(使用Maven antrun插件),我会得到以下错误: 发生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.FT
Maven antrun插件
),我会得到以下错误:
发生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
ant-CommonNet.jar显然可供ant使用:
$ ls $ANT_HOME/lib | grep ant-commons-net
ant-commons-net.jar
Ant类路径是为maven antrun插件单独定义的,还是我遗漏了什么?有一个
类路径
属性,可以在maven antrun插件
的
部分设置
比如说,
<property name="classpath" refid="maven.compile.classpath"/>
ant commons net.jar
显然可供ant使用
是的,但是Maven和Maven antrun插件
没有使用您的本地Ant安装
Ant类路径是为maven antrun插件
单独定义的,还是我遗漏了什么
使用未包含在Ant默认jar中的Ant任务的方法记录在(这肯定会有帮助):
要使用未包含在中的Ant任务,请执行以下操作:
Ant jar,如Ant可选或自定义
任务您需要添加依赖项
需要将任务运行到
插件类路径并使用
maven.plugin.classpath
referenceif
需要
<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>
4.0.0
我的测试应用程序
我的测试组
1.0-快照
org.apache.maven.plugins
maven antrun插件
1.6
ftp
部署
跑
公用网络
公用网络
1.4.1
蚂蚁
蚂蚁公地网
1.6.5
蚂蚁
蚂蚁结
1.6.5
正如Pascal所提到的,maven antrun插件没有使用您的$ant_HOME环境变量指定的ant,他所提到的配置可能是从纯maven的角度始终如一地做到这一点的最佳方法 但是,jar可以存储在$USER\u HOME/.ant/lib而不是$ant\u HOME/lib中,这些jar应该可以在该用户运行的任何ant实例的类路径上使用 注意您的ant脚本不能假设JAR存在,并且JAR仅在启动时放置在类路径上,因此如果脚本定义了一个安装目标以将JAR下载到$USER_HOME/.ant/lib中,那么该目标必须在“单独的ant会话”中运行,再次调用before和,以执行依赖于jar的任务
这种方法的唯一潜在好处是Ant脚本可以从maven和Ant运行。这是正确的方法。我唯一建议做的不同的事情是:1)指定<代码> Ant <代码> GyPID,而不是<代码> org。Apache。Ant <代码>,因为这是Maven插件内部引用的。如果这是一个多模块项目,你也应该考虑在根项目POM中添加依赖项到插件管理部分。这将防止项目中对antrun的其他引用破坏您的依赖关系。@Tim实际上,在
ant commons net
中,groupId
是org.apache.ant
,但上面的一个对于1.6.5版是正确的。换句话说,如果您想使用更新的版本,请调整它。关于pluginManagement
部分,您当然是对的。我会更新我的答案,提到。。。明天:)谢谢你的评论!