Reputation: 171
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
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
Reputation: 8169
Simplest way perhaps would be to start your java app via sudo, e.g.:
sudo 'java YourClass'
Upvotes: 1
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