如何从 Eclipse 以超级用户身份运行我的应用程序? [英] How do I run my application as superuser from Eclipse?
问题描述
当我尝试从 Eclipse 运行我的服务器应用程序时遇到错误.错误是java.net.BindException:权限被拒绝.我认为这是因为我使用端口 443 来设置 SSL 连接.如果我使用 java 和 sudo 在命令行上运行我的代码,我可以解决这个问题.有没有办法设置 Eclipse,以便当我点击运行按钮时,我的应用程序使用 sudo 执行?
您可以按照以下步骤以超级用户身份编译/调试应用程序.
重命名您的 Java 应用程序
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
<块引用>#!/bin/bash# 文件:/usr/lib/jvm/java-6-openjdk/jre/bin/java# descr:jdk 的启动器.以 root 身份运行 jdk 时# cmd-line-arg "--run-as-root" 被指定.#jre="/usr/lib/jvm/java-6-openjdk/jre/bin/java.ori"run_as_root=false参数=# 过滤命令行参数对于 "$@" 中的 arg做案例$arg"在--run-as-root) run_as_root=true;;*) args="$args $arg";;esac完毕# 删除前导空格args=$(echo $args | sed -e 's/^[ ]*//')如果 $run_as_root然后echo "警告:以 root 身份运行!"gksu "$jre $args"别的$jre $args菲
更改权限以使其可执行
sudo chmod 0755/usr/lib/jvm/java-6-openjdk/jre/bin/java
启动日食
- 转到窗口->首选项->Java->已安装的JRE
- 将 java-6-openjdk 复制到 java-6-openjdk-root
- 编辑 JRE 并添加--run-as-root"作为默认 VM 参数
要以 root 身份运行项目,您需要执行以下步骤:
- 转到项目->属性->Java构建路径
- 双击 JRE 系统库并在备用 JRE 中选择java-6-openjdk-root"
注意:这个想法来自 http:///www.eclipse.org/forums/index.php/mv/msg/87353/724852/#msg_724852
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.
Rename your java-application
sudo mv /usr/lib/jvm/java-6-openjdk/jre/bin/java /usr/lib/jvm/java-6-openjdk/jre/bin/java.ori
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/^[ ]*//') 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
Startup eclipse
- Go to Window->Preferences->Java->Installed JREs
- Duplicate java-6-openjdk to java-6-openjdk-root
- Edit JRE and add "--run-as-root" as Default VM Argument
To run projects as root you need to follow these steps:
- Go to Project->Properties->Java Build Path
- Double-Click the JRE System Library and choose in Alternate JRE "java-6-openjdk-root"
Note: The idea is from http://www.eclipse.org/forums/index.php/mv/msg/87353/724852/#msg_724852
这篇关于如何从 Eclipse 以超级用户身份运行我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!