如何从Eclipse中以超级用户身份运行我的应用程序? [英] How do I run my application as superuser from Eclipse?

查看:621
本文介绍了如何从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.


  1. 重命名你的java应用程序

  1. 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

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:


    1. 转到项目 - >属性 - > Java构建路径

    2. 双击JRE系统库和选择Alternate JREjava-6-openjdk-root

    注意:这个想法来自 http://www.eclipse.org/forums/index.php/mv/msg/ 87353/724852 /#msg_724852

    这篇关于如何从Eclipse中以超级用户身份运行我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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