【问题标题】:Using ant script within maven ant plugin在 maven ant 插件中使用 ant 脚本
【发布时间】:2013-04-26 22:46:01
【问题描述】:

我正在使用 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:\Development\documentation\build.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_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]

我已尝试添加必要的依赖项,如下所示:

<dependency>
    <groupId>ant</groupId>
    <artifactId>ant-optional</artifactId>
    <version>1.5.2</version>
</dependency>

我查看了 ant-optional jar 文件,并且确实存在类 org.apache.tools.ant.taskdefs.optional.PropertyFile。我试图将 jar 添加到 $ANT_HOME 内的 lib 目录中,但没有成功。任何光线都会被欣赏。

【问题讨论】:

  • 我不想在我的 pom 文件中明确包含目标,因为 ant 文件将继续在其他地方修改。

标签: maven ant


【解决方案1】:

您发布的错误消息显示您正在使用 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>

【讨论】:

    【解决方案2】:

    您的问题与插件相关,因此将正确的 jar 添加为普通的 &lt;dependency&gt; 不会解决问题。

    您需要将包含org.apache.tools.ant.taskdefs.optional.PropertyFile 的JAR 添加到%ANT_HOME%\lib

    依赖项是您项目的一部分,如果没有特殊配置,它们不会部署在您的 ANT 文件夹中。

    【讨论】:

    • 我怀疑maven类路径空间与蚂蚁使用的不一样,无论如何我也尝试将jar添加到lib文件夹中,我在问题“我尝试添加将 jar 放入 $ANT_HOME 内的 lib 目录中,但没有运气”。
    • 添加插件依赖是怎么回事?那应该可以...?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    相关资源
    最近更新 更多