How can I launch an external class outside the originator JVM without invoking Runtime.getRuntime().exec(...)?
I mean someting conceptually similar to Runtime.getRuntime().exec(...) but which allows to invoke directly开发者_Python百科 the class without calling exec("java -classpath $currentClasspath my.class.name")...
Just to notice that tools.jar has an useful java class for compiling specifically java sources, there is something similar for executing directly java classes?
String[] args = {"foo", "bar"};
my.pkg.MyClass.main(args);
Of course, you have to make sure that my.pkg.MyClass
is on your classpath at compile time and build time.
If you have a JAR and you know the API, you can call new on any class and run them as if they were your own. I am not sure what you are asking here. Of course main is just another method of a class, albeit a static one.
Calling exec starts the program in another process, which gives you certain benefits. You might be able to call main in another Thread if desired.
Maybe a little more detail would be good.
精彩评论