1

To make my program a bit more user friendly and easy to update, when it installs it creates a link to the .jar file is on the desktop.

The problem is- The file is not marked as executable, so the user would have to find a hidden directory and mark the jar file as executable. Blech.

I tried using:

Runtime.getRuntime().exec(new String[]{"sudo","chmod","+x",home+"/"+dir+"/DevChat.jar"});

, which, foresee-ably, requested the user's password which went without reply.

So is there any way I could A) Give runtime the user's password after prompting the user for it, B) Make the link run the command "java -jar blahblahblah.jar", or C) Write an install script that marks the file as executable?

J3RN
  • 1,470
  • 3
  • 19
  • 26

3 Answers3

0

You don't need to be root to change the permissions of a filesystem object you own.

Ignacio Vazquez-Abrams
  • 699,552
  • 132
  • 1,235
  • 1,283
  • By George... you're right! Tons of thanks! A tutorial on bash had me thinking root was necessary... Cheers! – J3RN Mar 04 '12 at 00:49
0

As someone said ... you don't need to be root to change the permissions of the jar file.
However, in case this file is placed in a folder where administrator privileges are needed to access it or there is no workaround for that just use the -S option when running sudo.
For reference check here: Getting stdin from sudo command ;)
Cheers pal!

P.S.: Of course, you have to open a stream and then get that from the terminal which I assume is trivial in your case. If you do have a problem however just ask.

Community
  • 1
  • 1
Kounavi
  • 1,021
  • 1
  • 12
  • 24
0

Since you created a link in the desktop, I'm going to assume you want some kind of GUI based intereaction with the user.

If so, just use gksudo instead of sudo.

   Runtime.getRuntime().exec(new String[]{"gksudo","chmod","+x",home+"/"+dir+"/DevChat.jar"});

If you need something a bit more complex, take a look at Zenity.

  • Hey, that's brilliant! While it may not be used in this application, this will definitely come in handy! – J3RN Mar 06 '12 at 12:37