如何在不调用 Runtime.getRuntime().exec(...) 的情况下在发起者 JVM 之外启动外部类?
我的意思是概念上类似于 Runtime.getRuntime().exec(...) 但允许直接调用类而不调用 exec("java -classpath $currentClasspath my.class.name")...
只是要注意tools.jar 有一个有用的 java 类,用于专门编译 java 源,有类似的东西可以直接执行 java 类吗?
I mean someting conceptually similar to Runtime.getRuntime().exec(...) but which allows to invoke directly 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,您必须确保在编译时和构建时
my.pkg.MyClass
位于您的类路径中。Of course, you have to make sure that
my.pkg.MyClass
is on your classpath at compile time and build time.如果您有 JAR 并且了解 API,则可以在任何类上调用 new 并运行它们,就好像它们是您自己的类一样。我不确定你在这里问什么。当然,main 只是类的另一种方法,尽管是静态方法。
调用 exec 在另一个进程中启动程序,这会给您带来一定的好处。如果需要,您可以在另一个线程中调用 main。
也许更详细一点会更好。
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.