mac如何运行java游戏,如何在Mac上从Java启动另一个应用程序

The code I wrote that works fine on Windows is not working on the Mac.

The short form I am calling:

Runtime.getRuntime().exec (String ["/Applications/CM Battle for Normandy/CM Battle for Normandy.app" "2vs2 White Manor 072.ema"], null, "/Applications/CM Battle for Normandy/");

There is no file association setup with .ema files by the software I am trying to run (it's a game if you are curious)

My code looks like this:

private void launchGameProgram (PBEMGame selectedGame) {

if (selectedGame == null)

return; // no work to do

InstalledProgram program = selectedGame.playedWith ();

if (program == null)

return; // no work to do

try {

Vector command = new Vector ();

command.add (program.getExeFile ().getAbsolutePath ());

if (selectedGame.getLastTurn () != null && selectedGame.getLastTurn ().getTurnFile () != null) {

// Add the turn file name to the command

command.add (selectedGame.getLastTurn ().getTurnFile ().getName ());

}

GUIApplicationPolicy.getLog ().log ("WTII testing: About to launch: " + command.toString () + " from: " + program.getExeFile ().getParentFile ());

Runtime.getRuntime ().exec (command.toArray (new String[command.size ()]), null, program.getExeFile ().getParentFile ());

} catch (IOException exception) {

GUIApplicationPolicy.getLog ().log (exception);

exception.printStackTrace();

}

}

This produces the following in the log:

!Entry: 2013/10/02 23:08:33.017

!Message: WTII testing: About to launch: [/Applications/CM Battle for Normandy/CM Battle for Normandy.app, 2vs2 White Manor 072.ema] from: /Applications/CM Battle for Normandy

!Entry: 2013/10/02 23:08:33.023

!Exception: Cannot run program "/Applications/CM Battle for Normandy/CM Battle for Normandy.app" (in directory "/Applications/CM Battle for Normandy"): error=13, Permission denied

!Stack: java.io.IOException: Cannot run program "/Applications/CM Battle for Normandy/CM Battle for Normandy.app" (in directory "/Applications/CM Battle for Normandy"): error=13, Permission denied

at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)

at java.lang.Runtime.exec(Runtime.java:617)

at com.lesliesoftware.whoseturnisit.WhoseTurnIsIt.launchGameProgram(Unknown Source)

at com.lesliesoftware.whoseturnisit.WhoseTurnIsIt.access$3100(Unknown Source)

at com.lesliesoftware.whoseturnisit.WhoseTurnIsIt$LaunchSelectedGameProgram.widgetSelected(Unknown Source)

at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)

at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)

at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3776)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1367)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1390)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1375)

at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1187)

at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3622)

at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3277)

at com.lesliesoftware.whoseturnisit.WhoseTurnIsIt.main(Unknown Source)

Caused by: java.io.IOException: error=13, Permission denied

at java.lang.UNIXProcess.forkAndExec(Native Method)

at java.lang.UNIXProcess.(UNIXProcess.java:135)

at java.lang.ProcessImpl.start(ProcessImpl.java:130)

at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)

... 14 more

Any help or guidance would be appreciated.

解决方案

Try this..

Runtime.getRuntime().exec (String ["open /Applications/CM Battle for Normandy/CM Battle for Normandy.app" "--args" "2vs2 White Manor 072.ema"], null, "/Applications/CM Battle for Normandy/")

UPDATE: After discussing with Ian..

Runtime.getRuntime().exec (String ["open" "/Applications/CM Battle for Normandy/CM Battle for Normandy.app" "--args" "2vs2 White Manor 072.ema"], null, "/Applications/CM Battle for Normandy/")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值