获取NetBeans的运行我使用sudo的项目? [英] Get netbeans to run my project with sudo?
问题描述
我工作在NetBeans项目需要运行的项目有root权限。
I am working on a project in netbeans that requires the running project to have root privileges.
我想它所以每次我按下运行项目(F6)我的项目是root身份运行,所以用的gksudo javac的主要相当于,因为它是有一个GUI。
I would like it so that each time I push "Run Project" (F6) my project is run as root, so with the equivalent of "gksudo javac Main", as it is has a GUI.
一个选项是用root权限,编辑为gksudo NetBeans的快捷键轻松完成启动NetBeans。但是,当我有多个项目在NetBeans这意味着,对每一个项目,我必须执行root权限的NetBeans,这不是我想要的。
One option is to start netbeans with root privileges, easily done by editing the shortcut to "gksudo netbeans". But as I have multiple projects in netbeans this has meant that for each project I must run netbeans with root privileges, this is not what I want.
另一种选择,当然,是简单地从shell中运行我的项目,但要么是不理想的。
Another option, of course, is to simply run my project from the shell, but this is not ideal either.
我觉得这是通过改变这个项目的build.xml文件可能的,但我有麻烦搞清楚如何。
I think this is possible by altering this projects build.xml file but am having trouble figuring out how.
经过一番研究,这将是看起来,这是一个相当Apache Ant的问题,我有机会到build.xml,我可以修改,所以我需要知道如何让蚂蚁运行我使用sudo / gksudo项目。但是,我想不出如何做到这一点,或者如果它是可能的。
After some research it would be seem that this is rather an Apache Ant question, I have access to build.xml which I can modify so I need to know how to get Ant to run my project with sudo/gksudo. However, I can't figure out how to do this or if it is possible.
推荐答案
假设这是一个Java SE的工程(而不是,比方说,一个Web应用程序或Ruby程序)。首先,关闭在保存时编译下的项目属性编译。
Assuming this is a "Java SE" project (as opposed to, say, a web app or a Ruby program). First, turn off Compile on Save under Compiling in project properties.
二,添加到的build.xml
:
<target name="-init-macrodef-java">
<macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
<attribute default="${main.class}" name="classname"/>
<attribute default="${run.classpath}" name="classpath"/>
<element name="customize" optional="true"/>
<sequential>
<exec executable="gksudo" failonerror="true">
<arg value="--"/>
<arg value="java"/>
<arg value="-classpath"/>
<arg path="@{classpath}"/>
<arg line="${run.jvmargs}"/>
<arg value="@{classname}"/>
</exec>
</sequential>
</macrodef>
</target>
有其他的东西,你可以微调,但这应该足以让你开始。
There are other things you can fine-tune but this should be enough to get you started.
这篇关于获取NetBeans的运行我使用sudo的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!