I am trying to get Oracle Java 7 update 3 working correctly on Debian 6. I have downloaded and set up the files in
/usr/java/jre1.7.0_03. I have also set the following two lines at the end of
export JAVA_HOME=/usr/java/jre1.7.0_03 export PATH=$PATH:$JAVA_HOME/bin
Logging in as other users and root is fine, Java can be found:
chris@mc:~$ java -version java version "1.7.0_03" Java(TM) SE Runtime Environment (build 1.7.0_03-b04) Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)
However there are two cases where Java cannot be found as detailed below. Note that both of these worked fine when I have previously installed OpenJDK Java 6 via aptitude, but I need Oracle Java 7 for various reasons.
Most importantly, I cannot run commands as another user via
su, despite the PATH showing that Java should be present. The user was created with
root@mc:~# su chris -c "echo $PATH" /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/java/jre1.7.0_03/bin:/bin root@mc:~# su chris -c "java -version" bash: java: command not found root@mc:~# su chris -c "/usr/java/jre1.7.0_03/bin/java -version" java version "1.7.0_03" ...
How can it be in the
PATHbut not be found? Update 05/04/2012: explained by Daniel, to do with it being a non-interactive shell so files such as
/etc/bash.bashrcare not executed. Doing a full swap to that user and running Java works:
root@mc:~# su chris chris@mc:/root$ java -version java version "1.7.0_03" ...
I run a script on start up which exhibits similar but slightly different problems. The script is located in
/etc/init.d/start-mystuff.shand calls a jar:
#!/bin/bash # /etc/init.d/start-mystuff.sh java -jar /opt/Mars.jar
I can confirm that the script runs on start up and the exit code is 127, which indicates command not found. Inserting a line to print/save the
PATHshows that it is:
This second problem isn't as important because I can just point directly to the Java executable in the script, but I am still curious!
I have tried setting the full
JAVA_HOME explicitly in
/etc/environment which didn't help. I have also tried setting them in
/etc/profile which doesn't seem to help either. I have tried logging in and out again after setting
PATH in the various locations (duh!).
Anyway, long post for what will probably have a simple one line solution :( Any help with this would be greatly appreciated, I have spent far too long trying to fix it by myself.
The first problem may seem obscure but in my system I have users that are not allowed SSH access yet I still want to run processes as them. I have a ton of scripts operating in this way and don't want to have to change them all.