Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run my application as superuser from Eclipse?

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?

like image 648
Ronald Avatar asked Apr 05 '10 18:04

Ronald


People also ask

How do I open root in Eclipse?

To run GUI applications as root you should not be using sudo , but instead use gksu . In this particular case run gksu eclipse , then enter your password.

How do I run an Eclipse application?

Click Run > Run... Select Eclipse Application in the left hand list of launch configuration types, and press New. In Main tab, enter for example MyApplication in the Name field. Choose in field Location your target workspace.


2 Answers

You can follow these steps to compile/debug applications as superuser.

  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

  2. 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 
  3. Change the permissions to make it executable

    sudo chmod 0755 /usr/lib/jvm/java-6-openjdk/jre/bin/java

  4. Startup eclipse

  5. Go to Window->Preferences->Java->Installed JREs
  6. Duplicate java-6-openjdk to java-6-openjdk-root
  7. Edit JRE and add "--run-as-root" as Default VM Argument

To run projects as root you need to follow these steps:

  1. Go to Project->Properties->Java Build Path
  2. 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

like image 76
rednammoc Avatar answered Oct 13 '22 10:10

rednammoc


Assuming you are on Linux (*nix), How about starting your eclipse session via a sudo command?

Such as

sudo ~/eclipse/eclipse 

Now whatever you do from eclipse will have the sudo context?

like image 41
ring bearer Avatar answered Oct 13 '22 12:10

ring bearer