我正在使用ant maven插件在maven构建中调用遗留目标。当我运行pom文件时,它会在丢失的ant文件上抛出一个错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (clear-generated-javascripts) on project documentation: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] C:Developmentdocumentationbuild.xml:308: Problem: failed to create task or type propertyfile
[ERROR] Cause: the class org.apache.tools.ant.taskdefs.optional.PropertyFile was not found.
[ERROR] This looks like one of Ant's optional components.
[ERROR] Action: Check that the appropriate optional JAR exists in
[ERROR] -ANT_HOMElib
[ERROR] -the IDE Ant configuration dialogs
[ERROR]
[ERROR] Do not panic, this is a common problem.
[ERROR] The commonest cause is a missing JAR.
[ERROR]
我已经尝试添加必要的依赖项,如下所示:
<dependency>
<groupId>ant</groupId>
<artifactId>ant-optional</artifactId>
<version>1.5.2</version>
</dependency>
我查看了anti -optional jar文件,类org.apache.tools.ant.taskdefs.optional.PropertyFile确实在那里。我试图将jar添加到$ANT_HOME中的lib目录中,但没有成功。
您发布的错误信息显示您正在使用maven-antrun-plugin:1.3。我已经找到了不同的解决方案,分别使用插件的1.3版本和1.7版本。
Ant build . xml
<project name="ant-propertyfile" basedir=".">
<target name="run">
<propertyfile file="my.properties" comment="My properties">
<entry key="progress" value="Made"/>
</propertyfile>
</target>
</project>
maven-antrun-plugin: 1.3 pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
<ant antfile="build.xml" target="run"/>
</tasks>
</configuration>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-optional</artifactId>
<version>1.5.3-1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
maven-antrun-plugin: 1.7 pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<configuration>
<target>
<ant antfile="build.xml" target="run"/>
</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
您的问题是插件相关的,因此添加正确的jar作为正常的<dependency>
将无法解决问题。
您需要将包含org.apache.tools.ant.taskdefs.optional.PropertyFile
的JAR添加到%ANT_HOME%lib
依赖项是你项目的一部分,如果没有特殊的配置,它们不会部署在你的ANT文件夹中。