How to start “main” in a new Java process?

The question is simple How do I start a main method in another java process? Now I do this:

startOptions = new String[] {"java","-jar","serverstart.jar"};
new ProcessBuilder(startOptions).start();

But they asked me not to use external Jar file serverstart. Jar obviously has a main method, but it can call the main method in another process instead of calling it. Jar file?

I was thinking about something like this:

new ProcessBuilder(ServerStart.main(startOptions)).start();

But I don't know if there is such a thing

Cordial greetings,

Solution

Assuming that a new thread and a new class loader are not enough (although I will vote for this solution), I understand that you need to create a unique process and call a main method. In a class, it is not declared as "jar main method" in the manifest file - because you don't have a unique serverstart It's too late

In this case, you can simply call Java -cp $yourclasspath your package. Server start, just as you run any Java application without (or do not want to use) manifest main class

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>