IntelliJ-以Sudo身份运行程序 [英] IntelliJ - Running Program as Sudo

查看:538
本文介绍了IntelliJ-以Sudo身份运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java和IntelliJ在OSX上开发程序.处理网络套接字和ICMP.因此,该程序需要在OSX上以root或sudo的身份运行.程序可以在sudo下从IntelliJ外部的终端窗口正常运行.但是,我想从IntelliJ(V9)调试并运行它.在IntelliJ中,它出错(我需要root priv来枚举网络设备).我知道如何在IntelliJ中传递程序和VM参数,但是现在该如何命中Run和/Debug并使其在sudo下运行?基本上需要的是sudo java ...... MyProgram而不是java ..... MyProgram任何想法或解决方法.

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.

推荐答案

我想出了一个答案,想分享一下,以防万一其他人遇到这个问题.为了解决问题,我从QT& amp;的工作中汲取了灵感. QT Creator在进行网络编程时.

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.

在OSX上,我打开了一个终端窗口,然后将其CD到/Applications/IntelliJ IDEA 9.0.3.app/Contents/MacOS.在那里,您会找到一个名为idea的文件,它将启动IDE.我以sudo(sudo ./idea)的身份运行它.这样就可以处理对Intellij启动的所有内容的权限,并且我可以根据需要调试并逐步执行我的代码.

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.

这篇关于IntelliJ-以Sudo身份运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆