如何根据 Eclipse 中的变量设置 Ant 属性? [英] How to set Ant properties based on variables in Eclipse?

查看:26
本文介绍了如何根据 Eclipse 中的变量设置 Ant 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个常见问题,可能有无数种方法可以解决它.我正在为这种典型情况寻找一种优雅、简单的解决方案:

I have a common problem and there are probably countless ways to solve it. I'm looking for an elegant, simple solution to this typical scenario:

我在 Eclipse 中有一个带有 Ant 构建文件 (build.xml) 的项目,该构建文件使用一个属性文件 (build.properties).在那个属性文件中,我想设置一个指向eclipse项目根目录的属性,例如:

I have a project in Eclipse with an Ant build file (build.xml) the build file uses a property file (build.properties). In that property file, I want to set a property that points to the root directory of the eclipse project such as:

project.root = /path/to/eclipse/workspace/projectName

或者最好:

project.root = ${path.to.eclipse.workspace}/projectName

我该如何做到这一点:

  1. 在具有不同路径到项目根目录的不同机器上工作(即在团队环境中)
  2. 允许在 eclipse 中执行 ant build.xml 文件
  3. 允许 ant build.xml 文件在 eclipse 之外执行(即从命令行)
  4. 允许 build.properties 文件存在于项目根目录以外的目录中

推荐答案

我想我正在寻找的是将以下内容添加到 build.properties 文件中:

I think what I'm looking for is to add the following to the build.properties file:

project.root = ${basedir}

或者,我可以在需要 project.root 时使用 basedir 属性.

alternatively, I can just use the basedir property whenever project.root is needed.

我碰巧在看ivy.properties 的源代码,我看到正在使用 basedir 属性.我刚刚测试并验证了这个属性在 eclipse 内部和命令行以及从不同目录调用 ant 时在不同的机器上工作,例如:

I happened to be looking at the source code for ivy.properties and I saw the basedir property being used. I just tested and verified that this property works on different machines both from inside eclipse and from the command line as well as when making a call to ant from a different directory such as:

ant -f /path/to/eclipse/workspace/projectName/build.xml

一分钟后,我将验证在不同位置(例如在 src/main/resources/config/ivy/ivysettings.xml 中)导入属性文件时这是否也有效.

When I get a minute, I will verify that this also works when importing the property file in different locations (such as inside src/main/resources/config/ivy/ivysettings.xml).

这篇关于如何根据 Eclipse 中的变量设置 Ant 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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