简体   繁体   English

如何使用以root身份运行的jar捆绑程序为jar文件创建.app warpper

[英]How to create a .app warpper for a jar file using jar bundler that runs as root

I wrote an app in Java for Mac OS X. I want to convert it to a .app using Jar Bundler. 我用Java为Mac OS X编写了一个应用程序。我想使用Jar Bundler将其转换为.app。 I need this app to run as root though. 我需要这个应用程序以root身份运行。 Is there any way to make the app invoke a password prompt dialog such as this? 有什么方法可以使应用程序调用这样的密码提示对话框?

Yeah, You can use applescript. 是的,您可以使用applescript。 Forgive me, there might be a better way to do this, but this is how I would do it (its more fun this way too). 原谅我,也许会有更好的方法来做到这一点,但这就是我要做的(这种方式也更有趣)。

This runs a shell script 这运行一个shell脚本

Process proc=Runtime.getRuntime().exec("shell-script-here");

Then you take the next step, run an applescript through the shell script like this... 然后进行下一步,像这样通过shell脚本运行一个AppleScript。

Process proc=Runtime.getRuntime().exec("osascript -e 'applescript-here'");

You have to be really careful to backslash quotations and whatnot... but this line should prompt a password dialog 您必须非常小心,以反斜杠将引号引起来,但不行...但是此行应提示输入密码对话框

Process proc=Runtime.getRuntime().exec("osascript -e 'do shell script \"\" with administrator privileges');

Although that might seem confusing, when I say 'do shell script \\"\\"' to mean, do nothing, but it will still prompt for a password. 尽管这似乎令人困惑,但是当我说“执行shell脚本\\“ \\”“的意思时,什么也不做,但仍会提示您输入密码。 Given that I don't know what your program does, you can replace that with whatever shell script or something. 鉴于我不知道您的程序是做什么的,您可以用任何shell脚本或类似内容替换它。 Be clever with it, I'm sure you can figure out a way to make your program work given this. 聪明一点,我相信您可以在此基础上找到一种使程序正常工作的方法。

Now, I can't spoon-feed you the answer, just remember, in my experience, if you use this method, any errors will be due to not backslashing quotes or such. 现在,我无法为您提供答案,只是请记住,以我的经验,如果您使用此方法,则任何错误都将归因于不使用反斜杠等引起的。

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

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