Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ - Running Program as Sudo

Developing a program on OSX using Java and IntelliJ. Deals with network sockets and ICMP. Hence, the program needs to be run as root or sudo'd on OSX. Program runs fine from a terminal window outside IntelliJ under sudo. However, I would like to debug and run it from IntelliJ (V9). In IntelliJ it errors (I need root privs to enumerate network devices). I know how to pass program and VM parameters in IntelliJ but now how to hit Run and/Debug and have it run under sudo? What is needed is basically sudo java ...... MyProgram instead of java ..... MyProgram Any ideas or workarounds.

like image 671
J Henzel Avatar asked Dec 10 '10 21:12

J Henzel


People also ask

How do I give Sudo permission to IntelliJ?

Go to Settings/Preferences | Appearance & Behavior | System Settings | Process Elevation. Set the Keep 'sudo' authorization for (Keep UAC authorization for) checkbox and specify the value. The default is 15 minutes.

How do I run commands in IntelliJ?

Run commands Start typing the command name and navigate the suggestion list using the arrow keys. When you press Space , you accept the current suggestion and get further suggestions specific to this command. To get the list of available commands, type ? . The list of commands depends on the installed/enabled plugins.


2 Answers

I came out with an answer and wanted to share it just in case anyone else runs into this. To solve the problem, I took my cue from what I do with QT & QT Creator when doing network programming.

On OSX, I opened up a terminal window and cd'd down to/Applications/IntelliJ IDEA 9.0.3.app/Contents/MacOS. There you will find a file called idea which launches the IDE. I ran that as sudo (sudo ./idea). That took care of permissions on anything Intellij launched and I could debug and step through my code as needed.

sudo /Applications/IntelliJ IDEA 9.0.3.app/Contents/MacOS/idea  

Since this is a dev machine and I am in control of it security is not an issue in this case.

Hope it helps someone else out.

like image 167
J Henzel Avatar answered Sep 18 '22 20:09

J Henzel


Inside a terminal:

sudo -s 

give access to the root user.

from there you could run the Idea IDE using the script:

/Applications/IntelliJ\ IDEA*/bin/idea.sh 

and in this way I'm able to work on network where permission errors where printed before.

like image 27
p.g. Avatar answered Sep 21 '22 20:09

p.g.