简体   繁体   English

如何在MAC OS X上使用Sudo运行您的Java应用程序

[英]How to run your java app using Sudo on MAC OS X

Today i need your help :x I've seen a lot of answer but there are never full.. I want to launch my java app by another with 今天我需要你的帮助:x我已经看到了很多答案,但是从来没有完整..我想用另一个启动我的java应用程序

Runtime.getRuntime().exec("my command");

On the MAC OS X. Then i found that command: 在MAC OS X上。然后我发现命令:

#!/bin/sh
osascript -e "do shell script \"$*\" with administrator privileges"

What have i to change in this script to run my app like on linux which is: 我在这个脚本中有什么要改变来运行我的应用程序,就像在linux上一样:

Runtime.getRuntime().exec("gksudo java -jar myjar");

I would like to have 我想拥有

Runtime.getRuntime().exec("osascript -e \"do shell script \\"$*\\" with administrator privileges");

but is it possible ? 但这可能吗? thanks for you anwser :/ 谢谢你anwser:/

Call the osascriptWrapper.sh script from Java: 从Java调用osascriptWrapper.sh脚本:

Runtime.getRuntime().exec("/path/to/osascriptWrapper.sh myjar.jar");

Define osascriptWrapper.sh as: 将osascriptWrapper.sh定义为:

#!/bin/bash

osascript -e "do shell script \"/path2/to2/runJar.sh $*\" with administrator privileges"

And runJar.sh: 和runJar.sh:

#!/bin/bash

java -jar $*

您可以像在linux上一样在mac上使用sudo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM