使用 antcontrib通过 maven-antrun-plugin 执行任务
我的 maven java 项目使用 maven-antrun-plugin 来执行部署我的应用程序的deploy.xml ant脚本。 deploy.xml 使用
任务,这似乎导致了问题;
[INFO] 执行任务
[taskdef] 无法从资源 net/sf/antcontrib/antlib.xml 加载定义。找不到。部署:
[信息] ---------------------------------------------------------- --------------------------
[错误] 构建错误
[信息] ---------------------------------------------------------- --------------------------
[信息] 发生 Ant BuildException:执行此行时发生以下错误:
E:\My_Workspace\xxxxxx\xxxxxx\xxxxxxx\deploy.xml:24:问题:无法创建任务或键入 if
原因:名称未定义。
操作:检查拼写。
操作:检查是否已声明任何自定义任务/类型。
操作:检查是否存在任何/ 。声明已经发生。
这是我的 pom 中的 antrun 插件配置;
<plugin>
<inherited>false</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>remote-deploy</id>
<phase>install</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath"/>
<property name="compile_classpath" refid="maven.compile.classpath" />
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
<ant antfile="${basedir}/deploy.xml">
<target name="deploy" />
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</plugin>
..这是我的deploy.xml中的相关部分;
<target name="deploy" if="deploy">
<if> <!-- line 24 -->
<and>
为什么我查看我的 Maven 存储库,我可以看到 ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar
,当我查看 jar 内部时,我可以看到 net /sf/antcontrib/antcontrib.properties
所以没有问题。
当我检查 maven.compile.classpath
、maven.compile.classpath
和 maven.compile.classpath
的值时,我看不到任何参考 antcontrib
,这可能是问题所在吗?为什么当 antcontrib
被定义为依赖项时它们不出现?
My maven java project uses the maven-antrun-plugin to execute a deploy.xml ant script that deploys my app. The deploy.xml uses the <if>
task and this seems to be causing the problem;
[INFO] Executing tasks
[taskdef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.deploy:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: The following error occurred while executing this line:
E:\My_Workspace\xxxxxx\xxxxxx\xxxxxxx\deploy.xml:24: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Here is the antrun plugin config from my pom;
<plugin>
<inherited>false</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>remote-deploy</id>
<phase>install</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath"/>
<property name="compile_classpath" refid="maven.compile.classpath" />
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
<ant antfile="${basedir}/deploy.xml">
<target name="deploy" />
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</plugin>
.. and here is the relevant section from my deploy.xml;
<target name="deploy" if="deploy">
<if> <!-- line 24 -->
<and>
Why I look in my maven repo I can see ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar
and when I look inside the jar I can see net/sf/antcontrib/antcontrib.properties
so no problem there.
When I check the values of maven.compile.classpath
, maven.compile.classpath
and maven.compile.classpath
I can't see any reference to antcontrib
, could this be the problem? Why don't they appear when antcontrib
is defined as a dependancy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为添加 ant 来编译类路径以运行 Maven 插件并不是一个好主意。
我使用 Maven 3.0.4,它通过为 ant-contrib 标签指定命名空间来工作,例如:
我的
maven-antrun-plugin
依赖项:I think it is not a very good idea to add ant to compile classpath in order to run maven plugin.
I use Maven 3.0.4 and it worked by specifying namespace for ant-contrib tags, for example:
My
maven-antrun-plugin
dependencies:我发现您需要在插件中包含 ant-contrib 依赖项,这将使 taskdef 标记能够找到 antcontrib.properties
I found that you need to include the ant-contrib dependency inside the plugin which will enable the taskdef tag to find antcontrib.properties
好的,我已经解决了。
将依赖项移出
标记并将它们与其他项目依赖项一起放入似乎已经成功了。OK, I've solved it.
Moving the dependencies out of the
<build><plugin>
tag and putting them in with the other project dependencies seems to have done the trick.另一个解决方案是:将 ant-contrib-1.0b3.jar 保存到路径中,然后像这样定义它,
然后
我将完整的代码示例放在这里,您可以下载 https://www.surasint.com/run-ant-with-if-from-maven/
another solution would be: keep the ant-contrib-1.0b3.jar to a path and then define it like this
then
I put full code example here which you can download https://www.surasint.com/run-ant-with-if-from-maven/