How to run a Mac application from Java?

I tried to execute the code below to run a standalone utility application that I created from an Apple script, but I got the error "No file or directory."

I put identical copies (for testing) in the project, dist, parent directories, but this did not help.

So my questions are: Is my call to launch the application bad (perhaps because it is not Windows exe)? How to run mac application from java?

thanks

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Runtime r=Runtime.getRuntime(); Process p=null; String s="MyLineInInput.app"; try { p = r.exec(s); } catch (IOException ex) { Logger.getLogger(AudioSwitcherView.class.getName()).log(Level.SEVERE, null, ex); } } 
+4
source share
2 answers

The Mac App Bunde is not an executable file; it is a folder with a special structure. It can be opened with the open command, passing the Bundle application path as an argument: open MyLineInInput.app .

EDIT: Better yet, use Desktop.getDesktop().open(new File("MyLineInInput.app"));

+5
source

All Articles