Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

February 4, 2013

ERRORS of using Runtime.getRuntime() and exec() in Eclipse

When I use Runtime.getRuntime().exec("java ArrayTest")to run a new java application, it failed and I got lots of errors.

Finally, I found the reasons and solutions:

Reasons:
JVM searches this ArrayTest.class under the bin directory,

then you should add -classpath bin to your exec().
Solutions:
  1. Runtime.getRuntime().exec("java -classpath D:\java\Practice\bin ArrayTest");
  2. Runtime.getRuntime().exec("java -classpath .\bin ArrayTest"); // root directory
  3. Runtime.getRuntime().exec("java -classpath bin ArrayTest");