[英]Override ANT_HOME property in command line
I am writing a Java RCP application, where I input a file path from user for ANT_HOME
and then evaluate the version for validation. 我正在编写Java RCP应用程序,在该应用程序中,我从用户输入了
ANT_HOME
的文件路径,然后评估该版本以进行验证。 However, when I set ANT_HOME
property as system property, the evaluation fails because the ant.bat
script contains 但是,当我将
ANT_HOME
属性设置为系统属性时,评估失败,因为ant.bat
脚本包含
rem %~dp0 is expanded pathname of the current script under NT
set DEFAULT_ANT_HOME=%~dp0..
if "%ANT_HOME%"=="" set ANT_HOME=%DEFAULT_ANT_HOME%
I do not need to update my ANT_HOME
but need to override the value so that path entered by the user can be evaluated for a valid/invalid ant
version for my application. 我不需要更新我的
ANT_HOME
但需要覆盖该值,以便可以为用户输入的路径评估我的应用程序的有效/无效ant
版本。
The issue occurs even when I am using my command line. 即使当我使用命令行时,也会出现此问题。 See below screenshot.
请参见下面的屏幕截图。
C:\Users\tunnikrishnan>echo %ANT_HOME%
E:\tools\apache-ant-1.8.4
C:\Users\tunnikrishnan>E:\tools\apache-ant-1.6.5\bin\ant.bat -version
Apache Ant(TM) version 1.8.4 compiled on May 22 2012
C:\Users\tunnikrishnan>
Can somebody guide me how can I get to workaround on this? 有人可以指导我如何解决此问题吗?
Change the environment variables of the ProcessBuilder
instance. 更改
ProcessBuilder
实例的环境变量。
ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
Map<String, String> env = pb.environment();
env.put("ANT_HOME", getUserAntHome());
pb.redirectErrorStream(true);
Process p = pb.start();
where getUserAntHome()
gets value from user input. 其中
getUserAntHome()
从用户输入获取值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.