Tady
Tady

Reputation: 171

how to develop java application in linux which runs with administrative privileges?

I am developing a java application in Linux which has to write to files which requires administratives privileges e.g. ftpaccess . Do you know if there is any way of making the java application to ask the user for password at its startup and then run with administrtive privileges or to provide the password when writing to the file???

Upvotes: 1

Views: 624

Answers (3)

Martijn Courteaux
Martijn Courteaux

Reputation: 68887

I would recommend to put your JAR somewhere and make a Launcher in the Gnome Menu or create a bash script (start.sh) to launch your JAR with sudo privileges.

Use as command or script this:

gksudo java -jar yourjar.jar

Upvotes: 1

maximdim
maximdim

Reputation: 8169

Simplest way perhaps would be to start your java app via sudo, e.g.:

sudo 'java YourClass'

Upvotes: 1

Cody S
Cody S

Reputation: 4824

If I'm not mistaken, you need the user to run the app with superuser privileges. I'd recommend wrapping anything you are using that requires the permissions in a try-catch block, and throw a meaningful Exception if the commands fail because of a lack of superuser permissions.

Upvotes: 7

Related Questions