running build.xml from java project
I am trying to run ant script from java project which, in turn, I have to make it as excutable jar file here is the way I have done:
Runtime rt = Runtime.getRuntime();
rt.exec("cmd /c start ant.bat -buildfile D:\\ant\\trail\\build.xml")
But I don't want to give full path for build.xml. Instead, I want it to take from current source directory.
I tried something like this
rt.exec("cmd /c start ant.bat -buildfile .\build.xml");
but I get an error showing that cannot find build.开发者_JAVA技巧xml, build failed
Relative directory in java program doesn't start from the src folder, but from the projects (in Eclipse) or the jar folder. Make sure you have the file in the correct path. Also, don't forget to escape the slash:
rt.exec("cmd /c start ant.bat -buildfile .\\build.xml");
精彩评论