开发者

How can I launch an external class outside the originator JVM without invoking Runtime.getRuntime().exec(...)?

开发者 https://www.devze.com 2023-01-07 12:00 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消