PDA

View Full Version : "sudo java" troubles



ubuntuuser
June 25th, 2006, 02:14 PM
Hello everybody,

I am forced to test certain jar-files as root. To do that, I type
sudo java -jar Simcap.jar Strangely, I get the following error message:
sudo: java: command not found This is pretty weird, because when I become root using "su" and type the same command w/o sudo, it works flawlessly. But still, even as root, when I run the command with sudo I get that message.

Where do I have to set the path for sudo?

Stromham
June 25th, 2006, 03:06 PM
you need to navigate to the bin/binary folder in the java sdk, java cannot find the command because your not in the commands root dir. ex. jar.exe is located in java sdk's bin folder, you must be in the bin folder to use the command.

Stromham
June 25th, 2006, 03:07 PM
or you may not be able to use the command with sudo.

ubuntuuser
June 25th, 2006, 03:27 PM
I'm sorry, but I don't understand your answer. I can do
sudo apt-get for example without being in the /usr/bin directory, because I have /usr/bin in my PATH variable. I also have /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/bin in PATH (in the first place), so why can't I do
sudo java Even if I do not use the -jar parameter I am still told that the command was not found. The java dir is in my PATH as well as in root's PATH.

Stromham
June 25th, 2006, 10:16 PM
maybe you just cannot use sudo with java commands??

kunnk
June 26th, 2006, 07:21 AM
maybe you just cannot use sudo with java commands??

"just cannot" is not a good answer, there must be reason why it does not work.

In my computer sudo java works fine. Maybe ubuntuuser should check, is java in root user PATH or not.

ubuntuuser
June 26th, 2006, 08:35 AM
The internet is full of examples where users are supposed to use "sudo java something". I also thougth about a path issue, but my regular user and root have exactly the same PATH variable set. The java dir is always the first dir in PATH.

bieber
June 26th, 2006, 12:30 PM
You could try making a link to the executable and putting it in the root of the /usr/bin directory as just "java." Or, if you wanted, try sudo su and then just type your command.

ubuntuuser
June 26th, 2006, 03:22 PM
Ok, I found the solution. There was a soft link called java in /usr/bin, but I didn't bother at first to look where it linked to. Well, the link was wrong, so I created a new one to the correct "java" binary, now it works.

santiagozky
June 26th, 2006, 04:37 PM
isnt it better to add the java bin directory to root's PATH ?

ubuntuuser
June 26th, 2006, 06:14 PM
isnt it better to add the java bin directory to root's PATH ?
I have the java dir in root's PATH, but it didn't work because of some reason I don't understand. After fixing the link in /usr/bin it works.