Samantha Catania Samantha Catania - 10 months ago 62
Java Question

Running Java Program Multiple Times on Mac

Q. Is there a way to have a java program run twice on a mac like on windows?


You do not specify if you want to start a simple .jar or an application-bundle so I will give examples for both. To run multiple instances of an application-bundle on OS X, you can use the following trick; open the Terminal and start the application with this command:

open -n /path/to/your/

Each time you call this command, a new instance is opened up.

Attention: Just because it is possible to start several instances does not mean it is a good idea to do so. Make sure you will not run into trouble with concurrent write-access of multiple instances with the same file.

If you are trying to run a jar, you can simply call

java -jar /path/to/your/java.jar

several times to start up several instances.

To start up the java-application from inside a java-application under OSX, you have to do something like this:

In the case of a simple jar:

File jarFile = new File("/path/to/your/jarFile.jar");
Runtime.getRuntime().exec(new String[] { "java", "-jar", jarFile.getAbsolutePath() });

In the case of an application bundle:

File jarFile = new File("/path/to/your/");
final String[] command = { "open", "-n", jarFile.getAbsolutePath() };