0

I want to run my Ant script i.e (build.xml) through my java program , following is part of mycode

 Runtime rt = Runtime.getRuntime();
 Process proc = rt.exec("build.xml");

but I'm getting the following error

java.io.IOException: Cannot run program "build.xml": CreateProcess error=2, The system cannot find the file specified
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
 at java.lang.Runtime.exec(Runtime.java:593)
 at java.lang.Runtime.exec(Runtime.java:431)
 at java.lang.Runtime.exec(Runtime.java:328)
 at com.infotech.RunCmd.main(RunCmd.java:12)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
 at java.lang.ProcessImpl.create(Native Method)
 at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
 at java.lang.ProcessImpl.start(ProcessImpl.java:30)
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
 ... 4 more

How to solve it?

Andrew Thompson
169k42 gold badges224 silver badges441 bronze badges
asked Jul 6, 2011 at 10:02
3
  • I think you are missing a few commands inside your rt.exec(..). Perhaps it should read rt.exec("ant [target]"). As it stands you are trying to execute an xml file. Commented Jul 6, 2011 at 10:05
  • shouldn't be you trying something Process proc = rt.exec("PATH/TO/ANT_HOME/ant [options] [target [target2 [target3] ...]]"); Commented Jul 6, 2011 at 10:05
  • If you are still having issues could you add to this question, otherwise could you please accept an answer :) Commented Nov 29, 2011 at 23:35

4 Answers 4

1

You should execute ant -buildfile build.xml, so use rt.exec("ant -buildfile build.xml"); (build.xml is not a command) if build.xml is not in the application folder, you will need to give its actual path.

answered Jul 6, 2011 at 10:06
Sign up to request clarification or add additional context in comments.

Comments

0

Is build.xml actually in the directory you are running from, have you tried putting the file directory path in rt.exec()?

answered Jul 6, 2011 at 10:05

Comments

0

You do not invoke "build.xml" from command line, but "ant" that looks for a "build.xml" in your current directory. So change your code (assuming ant launcher is accessible from your PATH) to:

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("ant");
answered Jul 6, 2011 at 10:06

1 Comment

here is my actual code , still iam getting error.Actally my build.xml which i want to run is in following path D:ant\trai; my Ant_Home is in D:apacheant\bin
0

For a start, the executable is ant. The command parameter is build.xml.

Secondly, you need to use absolute paths for your files/executables or be sure of your runtime environment's directory

answered Jul 6, 2011 at 10:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.