如何从Eclipse运行我的应用程序作为超级用户? [英] How do I run my application as superuser from Eclipse?
问题描述
当我尝试从Eclipse运行我的服务器应用程序时,我遇到了错误。错误是 java.net.BindException:Permission denied 。我认为这是因为我使用端口443设置SSL连接。我可以解决这个问题,如果我在命令行上使用java和sudo运行我的代码。有一种方法来设置Eclipse,以便当我点击运行按钮,我的应用程序执行sudo?
I'm running in to an error when I try to run my server application from Eclipse. The error is java.net.BindException: Permission denied. I think this is because I am using port 443 to set up an SSL connection. I can get around this problem if I run my code on the command line using java and sudo. Is there a way to set up Eclipse so that when I hit the run button, my application is executed with sudo?
推荐答案
您可以按照以下步骤以超级用户身份编译/调试应用程序。
You can follow these steps to compile/debug applications as superuser.
-
重命名您的java应用程序
Rename your java-application
sudo mv / usr / lib / jvm / java-6-openjdk / bin / java /usr/lib/jvm/java-6-openjdk/jre/bin/java.ori
sudo mv /usr/lib/jvm/java-6-openjdk/jre/bin/java /usr/lib/jvm/java-6-openjdk/jre/bin/java.ori
创建以下脚本并将其存储为/ usr / lib / jvm / java-6-openjdk / jre / bin / java
Create following script and store it as /usr/lib/jvm/java-6-openjdk/jre/bin/java
#!/bin/bash
# file: /usr/lib/jvm/java-6-openjdk/jre/bin/java
# descr: Starter for jdk. Runs jdk as root when
# cmd-line-arg "--run-as-root" is specified.
#
jre="/usr/lib/jvm/java-6-openjdk/jre/bin/java.ori"
run_as_root=false
args=
# Filter command-line argument
for arg in "$@"
do
case "$arg" in
--run-as-root) run_as_root=true
;;
*) args="$args $arg"
;;
esac
done
# Remove leading whitespaces
args=$(echo $args | sed -e 's/^[ \t]*//')
if $run_as_root
then
echo "WARNING: Running as root!"
gksu "$jre $args"
else
$jre $args
fi
更改权限以使其可执行
Change the permissions to make it executable
sudo chmod 0755 / usr / lib / jvm / java-6-openjdk / jre / bin / java
sudo chmod 0755 /usr/lib/jvm/java-6-openjdk/jre/bin/java
启动eclipse
要以root身份运行项目,您需要执行以下步骤: p>
To run projects as root you need to follow these steps:
- 转到Project-> Properties-> Java Build Path
- 双击JRE系统库选择替代JREjava-6-openjdk-root
注意:这个想法来自http://www.eclipse.org/forums/index.php/mv/msg/87353/724852/# msg_724852
这篇关于如何从Eclipse运行我的应用程序作为超级用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!