J Henzel
J Henzel

Reputation: 2341

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.

Upvotes: 47

Views: 109896

Answers (5)

Milan
Milan

Reputation: 2023

I know this is not what OP directly asked - In case someone needs to do this on Linux (Ubuntu), e.g. in order to update Idea, just run from command line:

sudo /usr/local/bin/idea

Only make sure once the Update and Restart is finished to actually close Idea and start it normally

Upvotes: 3

sunny
sunny

Reputation: 1945

I agree with @Darron, it is not recommended to execute IntelliJ with sudo. You can execute with IntelliJ terminal instead. I maintain my project in IntelliJ. When I need to execute a unit test that requires sudo access, I just open IntelliJ terminal and type:

sudo gradle test

Good luck!

Upvotes: 0

J Henzel
J Henzel

Reputation: 2341

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.

Upvotes: 70

p.g.
p.g.

Reputation: 59

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.

Upvotes: 5

Darron
Darron

Reputation: 21620

Debugging of sudo programs is disallowed by the operating system unless the debugger is running as root, for security reasons.

So, even if you can figure out how to get IntelliJ to use sudo it won't do you any good.

Upvotes: 3

Related Questions