如何从Java运行Mac应用程序? [英] How to run a Mac application From Java?
问题描述
我尝试使用下面的代码来运行我从Apple脚本创建的独立实用程序应用程序但是,我收到了No File或Directory Exists错误。
我把在项目,dist,父目录中相同的副本(用于测试)但是,它没有帮助。
所以,我的问题是:
我的电话运行应用程序坏(可能是因为它不是Windows exe)?
如何从java运行mac应用程序?
谢谢
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
// TODO在这里添加你的处理代码:
Runtime r = Runtime.getRuntime();
过程p = null;
String s =MyLineInInput.app;
try {
p = r.exec(s);
} catch(IOException ex){
Logger.getLogger(AudioSwitcherView.class.getName())。log(Level.SEVERE,null,ex);
}
}
Mac App Bunde不是可执行文件,它是一个具有特殊结构的文件夹。可以使用 open
命令打开它,将App Bundle路径作为参数传递:打开MyLineInInput.app
。<编号:
更好的是使用 Desktop.getDesktop()。open(new File(MyLineInInput.app));
I tried the code below to run a stand-alone utility app I created from Apple script but, I get a No File or Directory Exists error.
I put identical copies (for testing) in the project, dist, parent directories but, it didn't help.
So, my questions are: Is my call to run the app bad (perhaps because it's not a Windows exe)? How to run a mac app 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);
}
}
A Mac App Bunde is not an executable file, it's a folder with a special structure. It can be opened using the open
command, passing the App Bundle path as an argument: open MyLineInInput.app
.
EDIT:
Even better would be using Desktop.getDesktop().open(new File("MyLineInInput.app"));
这篇关于如何从Java运行Mac应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!