Launch multiple java applications from one java application

871 views Asked by At

Let's say that I have Client class with a main method that does something (maybe connecting to class Server).

Is there a way to create a class (let's say ClientLauncher) that launch n clients (n passed as a parameter) as different java applications?

Note that, I do not want these clients to be different threads inside one application. I want to obtain the same effect that I would get by pressing the run button in Eclipse several times (launching different main methods).

1

There are 1 answers

1
dogant On BEST ANSWER

I'm not sure why you don't want to run clients using threads, Runtime.getRuntime().exec() can invoke extarnal jars within a class

Process run= Runtime.getRuntime().exec("java -jar jarpath_here");

If you put this in loop you'd have multiple processes.