I try to using Runtime but have some problem. I want to use Runtime.exec("java -cp")
. One is jar file, another is class file. Class file is refer to jar file but not included. Below is my code
Runtime rt = Runtime.getRuntime();
Process proc = null;
System.out.println(Run.class.getResource("").getPath());
try {
proc = rt.exec("java -cp c:/data/hh.jar; com/list/shark/Whale");
} catch (IOException e1) {
e1.printStackTrace();
}
Result is "could not find or load default class". I really want to know that where is location executing runtime and how sole this problem.
PS In local cmd, command is working.
The command you are using is wrong.
For running a jar from command line:
If you did not create a manifest file in your jar,
java -jar
will not work. Then you will need to specify the FQP (fully-qualified classpath) explicitely in the command:There is a good answer on how to create and run jar that you might want to check out