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.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论