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:
-
-
Runtime.getRuntime().exec("java -classpath D:\java\Practice\bin ArrayTest");
-
Runtime.getRuntime().exec("java -classpath .\bin ArrayTest"); // root directory
-
Runtime.getRuntime().exec("java -classpath bin ArrayTest");