Results 1 to 7 of 7
- 02-02-2009, 03:36 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
Run ant scripts using ProcessBuilder
This is what I have done so far:
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class BuildClass {
public BuildClass() {
}
public static void main (String args[]) throws Exception{
String s = null;
ProcessBuilder pb = new ProcessBuilder();
Map<String,String> env = pb.environment();
String path=null;
if(env.containsKey("Path")){
path=env.get("Path");
}
path=path+";C:\\ANT 1.7.0\\bin\\;";
env.put("JAVA_HOME","C:\\Program Files\\Java\\jdk1.5.0_10");
env.put("Path",path);
pb.redirectErrorStream(true);
pb.directory(new File("C:/xyz/pqr/uvw/"));
pb.command("ant","jar");
Process p = pb.start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
}
}
----------------
When i run this i get:
Exception in thread "main" java.io.IOException: CreateProcess: ant jar error=2
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 :451)
at BuildClass.main(BuildClass.java:51)
Java Result: 1
But if I change pb.command("ant","jar"); to pb.command("notepad");
Its working fine.
Could anyone help
- 02-11-2009, 07:04 AM #2
Member
- Join Date
- Oct 2008
- Posts
- 68
- Rep Power
- 0
Can you check if ant.bat is in PATH variable?
you may also want to try ant.bat instead of only ant.
____________________________________________
Priya,
Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | Dal| SnacksCheers,
Eat Healthy Stay Fit
- 02-11-2009, 07:15 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
I have already put the ant in the path :
path=path+";C:\\ANT 1.7.0\\bin\\;";
- 02-11-2009, 07:33 AM #4
Member
- Join Date
- Oct 2008
- Posts
- 68
- Rep Power
- 0
try C:\\ANT 1.7.0\\bin\\ant instead of just ant
and see if it gives same error?
____________________________________________
Priya,
Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | Dal| SnacksCheers,
Eat Healthy Stay Fit
- 02-11-2009, 07:35 AM #5
Member
- Join Date
- Oct 2008
- Posts
- 68
- Rep Power
- 0
also try without "jar" option ... let me know if that works....
____________________________________________
Priya,
Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | Dal| SnacksCheers,
Eat Healthy Stay Fit
- 02-11-2009, 07:46 AM #6
Member
- Join Date
- Oct 2008
- Posts
- 68
- Rep Power
- 0
I am able to run this using this line
pb.command("ant.bat", "jar");
its related to the name of the file then....
____________________________________________
Priya,
Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | Dal| SnacksCheers,
Eat Healthy Stay Fit
- 02-11-2009, 10:26 AM #7
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
If you see the code I have set the path:
Map<String,String> env = pb.environment();
String path=null;
if(env.containsKey("Path")){
path=env.get("Path");
}
path=path+";C:\\ANT 1.7.0\\bin\\;";
env.put("JAVA_HOME","C:\\Program Files\\Java\\jdk1.5.0_10");
env.put("Path",path);
----------
pb.command("C:\\ANT 1.7.0\\bin\\ant.bat","jar"); --- Only this works
pb.command("C:\\ANT 1.7.0\\bin\\ant","jar"); --- Even this does not work
pb.command("ant","jar"); --- this won't work
pb.command("ant.bat","jar"); --- this won't work
Need to know why?You have any idea
Similar Threads
-
bug (?) in ProcessBuilder.redirectErrorStream(true);
By gadasie in forum Advanced JavaReplies: 3Last Post: 03-13-2008, 09:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks