1

I am using below code,

Runtime runTime = Runtime.getRuntime();
Process p = runTime.exec("javac C:\\testDemo\\Demo.java");
p.waitFor();

Process p2= Runtime.getRuntime().exec("java Demo.class");
p2.waitFor();

it is creating a .class file, but its unable to run this program. do i need to do any change in Runtime.getRuntime().exec("java Demo.class"); method?

1
  • Why not run the other programs main method? Commented Jan 28, 2015 at 9:33

1 Answer 1

1

Change:

java Demo.class

To:

java C:\\testDemo\\Demo

Sign up to request clarification or add additional context in comments.

4 Comments

yeah i checked with that as well, still it's giving error like, Error: Could not find or load main class Demo.class
@Sam - Check the edit.. Give the full path, it will work.. unless ofcourse your javac fails. You should really read the output of the process doing javac.
@Sam on that case you should post the code of Demo.java
You should also try to manually run java C:\\testDemo\\Demo

Your Answer

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.