I have a command like this:
Ant Command:
<path-to-ant/bin/ant -f build.xml sql -lib <path-to-lib>/lib -Dhome=path-home -Ddev=path-to-dev -DsdkMode=install -DcompileSource.dest=path-to-dest -DOSTEMP=/tmp -D-BIFLocation=path-to-loation -DexecutionDirectory=path-exec-dir
At beggining, we use ProcessBuilder builder = new ProcessBuilder(command);
to run this, currentlyric we want to run it with ANT API, so we build it with ant Project.
I just build a method like:
// string value after "-f" is the location of buildFile
File buildFile = new File(antCommand.get((antCommand.indexOf("-f")+ 1)));
// string value before "-lib" is the target to run
String traget = antCommand.get((antCommand.indexOf("-lib")- 1));
Project project = new Project();
project.setUserProperty("ant.file", buildFile.getAbsolutePath());
project.init();
//set logger
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
project.addBuildListener(consoleLogger);
ProjectHelper projectHelper = ProjectHelper.getProjectHelper();
project.addReference("ant.projectHelper", projectHelper);
projectHelper.parse(project, buildFile);
project.executeTarget(traget);
But I do NOT know how to pass the parameter from the command line that starts with -D using Java.
Anyone have ideas or such experience? Thank you very much.