如何在 Ant 中从 Mavens 的 pom 中获取项目版本 [英] How to get project version from Mavens's pom in Ant

查看:27
本文介绍了如何在 Ant 中从 Mavens 的 pom 中获取项目版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 maven 项目和 ant 任务.在 ant 任务中,我想从 pom.xml 获取版本属性.如何获得?

I have maven project and ant task for it. In ant task i want to get version property from pom.xml. How to get it?

在 pom.xml 中:2.03.010

In pom.xml: <version>2.03.010</version>

推荐答案

Maven Ant 任务POM处理

要从 POM 访问版本,您可以使用以下命令:

To access the version from a POM, you can use the following:

<artifact:pom id="mypom" file="pom.xml" />

<echo>The version is ${mypom.version}</echo>

更新:使用任务.您将需要安装它们.安装说明

Update: To use the tasks. You will need to install them. Install instructions

您可以:

  1. 将 JAR 放在 Ant lib 目录中,并将其包含在 CLASSPATH 环境变量中
  2. 使用 -lib 命令行参数将其传递给 Ant
  3. 使用 typedef 声明.这允许您将 Ant Tasks 的库存储在您喜欢的任何位置,并将其放置在构建文件中.

使用选项 2. 您可以按如下方式修改您的项目以使 ant 了解 maven-ant-tasks 架构:

With option 2. you modify your project as follows to make ant aware of the maven-ant-tasks schema:

<project ... xmlns:artifact="antlib:org.apache.maven.artifact.ant">
  ...
</project>

使用选项 3.您指定 typedef 如下(假设 maven-ant-tasks jar 在您的项目的 lib 目录中):

With option 3. You specify the typedef as follows (assuming the maven-ant-tasks jar is in the lib directory of your project):

<project ... xmlns:artifact="antlib:org.apache.maven.artifact.ant">
  ...
  <path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.0.10.jar" />
  <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
       uri="antlib:org.apache.maven.artifact.ant"
       classpathref="maven-ant-tasks.classpath" />
  ...
</project>

这篇关于如何在 Ant 中从 Mavens 的 pom 中获取项目版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆