简体   繁体   中英

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. I need this app to run as root though. Is there any way to make the app invoke a password prompt dialog such as this?

Yeah, You can use 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

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

Then you take the next step, run an applescript through the shell script like this...

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. Given that I don't know what your program does, you can replace that with whatever shell script or something. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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