0

im new toward linux command.. Im using Mac Osx Mountain Lion as my operating system and eclipse to compile my java program..

The problem is that im trying to run/compile/debug my java application as root user on eclipse.

Following the step/answer from rednammoc in " How do I run my application as superuser from Eclipse? "

The step require me to write a executable script to make my jre to run as root user, however in the script there is a part where it uses the command gksu, which i assume only available on linux platform and not on Mac Osx platform and when i run my program, it show gksu command not found. So the question is,

  1. Can I some how install gksu on my Mac Osx?

  2. or is there any command that i can use to replace gksu?

Below are the script copied from the link,

#!/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
Community
  • 1
  • 1
Chris
  • 612
  • 2
  • 9
  • 23

2 Answers2

3

is there any command that i can use to replace gksu?

osascript -e 'on run argv' \
          -e 'do shell script (item 1 of argv) with administrator privileges' \
          -e 'end run' \
          "$jre $args"
Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
0

Hmm, I just found this over at http://pastebin.com/dhbU57uE haven't tried it yet, though!

#!/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

osascript -e 'on run argv' 
          -e 'do shell script (item 1 of argv) with administrator privileges' 
          -e 'end run' 
          "$jre $args"
Wulf
  • 379
  • 1
  • 6
  • 16
  • Nope. This does nothing. Ugh. Wish I understood what the heck the osascript answer above from Ian is trying to explain... – Wulf May 06 '15 at 01:51