执行 build.xml 文件后,我想检查build.xml中的一些属性来处理Java代码中的一些错误。
对于infos,我的Ant文件(build.xml)以这种方式执行(并非所有代码都存在):
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null,
ITaskLauncherConstants.LAUNCHER_NAME);
/* Configure the ILaunchConfiguration (not all setAttribute calls are presents) :*/
workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, "build.xml");
/* Launch the task, where monitor is a IProgressMonitor */
ILaunch lc = workingCopy.launch(ILaunchManager.RUN_MODE, monitor);
在我的build.xml文件中,我有一些属性:
<!-- In Ant File -->
<property name="fail.message" value="true" />
是否可以在Java代码中检查属性的内容?类似于:
/* In Java code */
lc.getProperty("fail.message");
当然,这意味着该类将“记录”build.xml属性。
6个月前问了同样的问题,但答案是行不通的(我试过):
Reading a .JPG Image and Saving it without file size change
感谢您的任何建议。
答案 0 :(得分:0)
一个简单的方法是在你的ant buildscript中使用echoproperties task,意味着将所有或所需的(通过echoproperties属性前缀)属性写入文件,然后在java中加载该文件。
从ant manual echoproperties,属性destfile:
如果指定,则该值指示要发送的文件的名称 声明的输出到。生成的输出文件是兼容的 由任何Java应用程序作为属性文件加载。如果不 指定,然后输出将转到Apache Ant日志。
<echoproperties prefix="fail" destfile="what/ever/foo.properties"/>