Reputation: 4533
I have an issue for my application.
I want to convert selected .java file to .class file at same path.
for that i am using:
File directoryPath = new File(".");
String command ="cmd.exe /C "+ directoryPath.getCanonicalPath()+"\\javac UpsOfferDataDaily.java";
Runtime.getRuntime().exec(command);
any thing strange with that??
It Can't execute my command successfully.
directory path will be same as the .java is situated.
what should i do...
Thanks in advance:
Upvotes: 0
Views: 548
Reputation: 8101
Try this....javac
is already in my path. So i jus gave the filename. Errors will be shown by the error stream, if any...It worked for me!!!
String command ="cmd.exe /C "+ "javac C:\\student\\workspace\\javaproject\\Testing\\src\\TestCalculator.java";
Process p = Runtime.getRuntime().exec(command);
InputStream i = p.getErrorStream();
int c;
while((c=i.read())!=-1)
System.out.print((char)c);
Upvotes: 2
Reputation: 5191
You could use the built-in api; javax.tool.JavaCompiler.
http://docs.oracle.com/javase/7/docs/api/javax/tools/JavaCompiler.html
http://www.javabeat.net/articles/73-the-java-60-compiler-api-1.html
Upvotes: 2