Question

I need to execute an external program from within my java application. I'm programming on a mac and have a .app application I'd like to run when the user selects it. It runs successfully on windows using:

String cmd = "path_to_executable\program.exe\"";

Process p = Runtime.getRuntime().exec(cmd); ...

But this does not work with an .app file. I've opened the contents of the .app file and have found a Unix executable file along with a other supporting files for the appliation. Is the unix executable file equivalent to an .exe file ?

Was it helpful?

Solution

Launching an Mac application from Java on OS X is just a matter of invoking the built-in open command with the Application as a parameter. The open command line tool in OS X knows how to correctly open many different file types, including application bundles. If you were trying to launch the TextEdit.app application, you would invoke:

open /Applications/TextEdit.app

In Java, you would use:

String cmd = "open /Application/TextEdit.app";
Process p = Runtime.getRuntime().exec(cmd);

OTHER TIPS

Yes, the executable that you should be running is the unix executable located in the .app bundle. It might not work properly though, you might need to cd into the directory or something.

Most application binaries are located in Contents/MacOS/App Name. You could make a method which would take in a string name and execute that binary based on the standard directory.

A .app file is really just a folder. It is a way to self contain applications on a Mac. The actual binary file is, most likely, the Unix executable you found. It would help to know some details about the app.

The binary files for a .app are located in Application.app/Contents/MacOS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top