【发布时间】:2020-11-09 13:00:31
【问题描述】:
尝试使用 maven pom.xml 文件中的 antrun 插件更改属性文件内容时出现以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (ant-create-properties
-file-content) on project SROTest: An Ant BuildException has occured: Problem: failed to create task or ty
pe 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_HOME\lib
[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]
[ERROR] This is not a bug; it is a configuration problem
[ERROR]
[ERROR] -> [Help 1]
这是我的 pom.xml 文件:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>Test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<suiteFile></suiteFile>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl -->
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxp-api</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ant-create-properties-file-content</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<propertyfile file="test.properties">
<entry key="browser" value="chrome"/>
<entry key="run_on_grid" value="true"/>
<entry key="hub_address" value="selenium-hub.service.mycompany.mgmt"/>
<entry key="take_screenshots_on" value="true"/>
<entry key="highlight_on" value="true"/>
<entry key="recording_video_on" value="false"/>
<entry key="run_with_KLB" value="false"/>
<entry key="sut_url" value="http://aaa/weblink400/1/backoffice.app?noplugin=1"/>
</propertyfile>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
此脚本的目标是更改属性文件内容,当使用 ant build.xml 文件和 ant 命令(cmd 命令)执行它时,它按预期工作,但是当尝试使用 maven 命令执行它时。我得到了上面显示的失败。
【问题讨论】:
-
首先,没有 Maven4 ;-) 。您可能使用 Maven 3.x。其次,错误表明您可能缺少用于 ant 任务的 jar。通常,ant run 插件需要额外的依赖项来运行 ant 任务。
-
如何将依赖添加到ant任务,我需要这个:
ant ant-junit 1.6.5