Where do the Java environment variables come from and how do I have them get set correcty?

I installed the latest Oracle Java sdk onto my new openSUSE 12.3 environment. I updated the update alternatives thing but the environment variables don’t follow suite. Sure I could set the variables manually with a script every time I start a java app but if they are in the env without my having done anything, can I at least have them come correctly?

me@host:~> env | grep -i java
JRE_HOME=/usr/lib64/jvm/java-1.5.0/jre
JAVA_BINDIR=/usr/lib64/jvm/java-1.5.0/bin
JAVA_HOME=/usr/lib64/jvm/java-1.5.0
SDK_HOME=/usr/lib64/jvm/java-1.5.0
JDK_HOME=/usr/lib64/jvm/java-1.5.0
JAVA_ROOT=/usr/lib64/jvm/java-1.5.0

What I did to set up the Oracle java:
/usr/sbin/update-alternatives --install /usr/bin/java java /usr/local/jdk1.7.0_17/bin/java 1
/usr/sbin/update-alternatives --install “/usr/lib64/browser-plugins/javaplugin.so” “javaplugin” “/usr/local/jdk1.7.0_17/jre/lib/amd64/libnpjp2.so” 20000
/usr/sbin/update-alternatives --set java /usr/local/jdk1.7.0_17/bin/java
/usr/sbin/update-alternatives --install /usr/bin/javac javac /usr/local/jdk1.7.0_17/bin/javac 1

me@host:~> which java
/usr/bin/java

me@host:~> ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Mar 18 22:04 /usr/bin/java -> /etc/alternatives/java

me@host:~> ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 31 Mar 19 20:58 /etc/alternatives/java -> /usr/local/jdk1.7.0_17/bin/java

me@host:~> cat .profile

Sample .profile for SuSE Linux

rewritten by Christian Steinruecken <cstein@suse.de>

This file is read each time a login shell is started.

All other interactive shells will only read .bashrc; this is particularly

important for language settings, see below.

test -z “$PROFILEREAD” && . /etc/profile || true

Most applications support several languages for their output.

To make use of this feature, simply uncomment one of the lines below or

add your own one (see /usr/share/locale/locale.alias for more codes)

This overwrites the system default set in /etc/sysconfig/language

in the variable RC_LANG.

#export LANG=de_DE.UTF-8 # uncomment this line for German output
#export LANG=fr_FR.UTF-8 # uncomment this line for French output
#export LANG=es_ES.UTF-8 # uncomment this line for Spanish output

Some people don’t like fortune. If you uncomment the following lines,

you will have a fortune each time you log in :wink:

#if -x /usr/bin/fortune ] ; then

echo

/usr/bin/fortune

echo

#fi

me@host:~> cat .bashrc

Sample .bashrc for SuSE Linux

Copyright (c) SuSE GmbH Nuernberg

There are 3 different types of shells in bash: the login shell, normal shell

and interactive shell. Login shells read ~/.profile and interactive shells

read ~/.bashrc; in our setup, /etc/profile sources ~/.bashrc - thus all

settings made here will also take effect in a login shell.

NOTE: It is recommended to make language settings in ~/.profile rather than

here, since multilingual X sessions would not work properly if LANG is over-

ridden in every subshell.

Some applications read the EDITOR variable to determine your favourite text

editor. So uncomment the line below and enter the editor of your choice :slight_smile:

#export EDITOR=/usr/bin/vim
#export EDITOR=/usr/bin/mcedit

For some news readers it makes sense to specify the NEWSSERVER variable here

#export NEWSSERVER=your.news.server

If you want to use a Palm device with Linux, uncomment the two lines below.

For some (older) Palm Pilots, you might need to set a lower baud rate

e.g. 57600 or 38400; lowest is 9600 (very slow!)

#export PILOTPORT=/dev/pilot
#export PILOTRATE=115200

test -s ~/.alias && . ~/.alias || true
richi@zwirgli:~>

My guess is that it’s with the script /etc/profile.d/alljava.csh . But shouldn’t this look at the “alternative” symlinks?

Regards,
Richard

On 2013-03-23 18:36, richardeigenmann wrote:
>
> I installed the latest Oracle Java sdk onto my new openSUSE 12.3
> environment. I updated the update alternatives thing but the environment
> variables don’t follow suite. Sure I could set the variables manually
> with a script every time I start a java app but if they are in the env
> without my having done anything, can I at least have them come
> correctly?
>
> me@host:~> env | grep -i java
>
> JRE_HOME=/usr/lib64/jvm/java-1.5.0/jre
> JAVA_BINDIR=/usr/lib64/jvm/java-1.5.0/bin
> JAVA_HOME=/usr/lib64/jvm/java-1.5.0
> SDK_HOME=/usr/lib64/jvm/java-1.5.0
> JDK_HOME=/usr/lib64/jvm/java-1.5.0
> JAVA_ROOT=/usr/lib64/jvm/java-1.5.0

In my system, these do not even exist. I don’t know who should create
them, and contents.

>
>
> What I did to set up the Oracle java:

I simply install the oracle rpm. It does not go to /usr/local/, but to
“/usr/java/jre1.7.0_17”.

> My guess is that it’s with the script /etc/profile.d/alljava.csh . But
> shouldn’t this look at the “alternative” symlinks?

That script is for cshell only. I figure that as java is not in the
usual location, the variables are not set.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On 03/23/2013 06:36 PM, richardeigenmann wrote:
> I installed the latest Oracle Java sdk onto my new openSUSE 12.3
> environment.

yep, imo one has to be a little lucky to get it right (Carlos was
born lucky!)

the last time i got it right i followed this
guide:http://sites.google.com/site/easylinuxtipsproject/java-for-opensuse

i really dislike not having a fool proof guide on a page among the
[whatever].opensuse.org but, that one worked for me, on openSUSE 11.4
Evergreen


dd
http://tinyurl.com/DD-Caveat
http://tinyurl.com/DD-Software

On 2013-03-24 01:17, dd wrote:
> On 03/23/2013 06:36 PM, richardeigenmann wrote:
>> I installed the latest Oracle Java sdk onto my new openSUSE 12.3
>> environment.
>
> yep, imo one has to be a little lucky to get it right (Carlos was born
> lucky!)

X’-)

>
> the last time i got it right i followed this
> guide:http://sites.google.com/site/easylinuxtipsproject/java-for-opensuse

Those are the instructions I followed :slight_smile:

Except that I deviate from them in that instead of the .tar.gz I use the
…rpm from the same oracle site.

> i really dislike not having a fool proof guide on a page among the
> [whatever].opensuse.org but, that one worked for me, on openSUSE 11.4
> Evergreen

I used the same method both on my 11.4 and 12.1. Let’s see my notes.
The first thing is removing the original Sun rpm that openSUSE 11.4 or
12.1 had. Yast will then install instead another java version, icetea or
whatever. This has to be allowed, because otherwise YaST will think that
there is no java installed and will then try to remove things like
LibreOffice.

So we need having two Java installations, one from Oracle (which
openSUSE does not “recognize”), and any other one that YaST does
recognize - even if you will not use it. So its life. :slight_smile:

Thus download the Oracle rpm, currently “jre-7u17-linux-x64.rpm”. Then
install it, with (from the directory where it is downloaded, in a
terminal as root:


rpm --install jre-7u17-linux-x64.rpm

And on the next version, you do instead:


rpm --upgrade jre-7u18-linux-x64.rpm

and you are finished, you don’t need to do anything else.

But the first time, you need using “update-alternatives”:



> Telcontar:~ # l /usr/bin/java
> lrwxrwxrwx 1 root root 22 Aug 21  2012 /usr/bin/java -> /etc/alternatives/java*
> Telcontar:~ # l /etc/alternatives/java
> lrwxrwxrwx 1 root root 26 Aug 21  2012 /etc/alternatives/java -> /usr/java/default/bin/java*
> Telcontar:~ # l /usr/java/default/bin/java
> -rwxr-xr-x 1 root root 7750 Mar  1 12:30 /usr/java/default/bin/java*
> Telcontar:~ # rpm -qf /usr/java/default/bin/java
> jre-1.7.0_17-fcs.x86_64
> Telcontar:~ #

> Telcontar:~ # update-alternatives --install "/usr/bin/java" "java" "/usr/java/default/bin/java" 1
> Telcontar:~ # update-alternatives --set java /usr/java/default/bin/java
> Telcontar:~ # update-alternatives --list java
> /usr/java/default/bin/java
> /usr/lib64/jvm/jre-1.6.0-openjdk/bin/java
> Telcontar:~ #

(I think the '1' above is because of the first line in --list - I don't
remember)

Then check:

> Telcontar:~ # java -version
> java version "1.7.0_17"
> Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
> Telcontar:~ #


Apparently, that’s all. It works, my java applications run. Mozilla test
is ok, too. You also need to do, for every user, this - if you want java
in firefox:


ln -s /usr/java/default/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

I think that there is another method that would work for every user at
once, but I don’t know it.

The remaining problem I have is this, apparently:


Telcontar:~ # env | grep -i java
Telcontar:~ #

And about this one I’m not sure what i should do, if anything. :-?


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On 2013-03-24 02:33, Carlos E. R. wrote:
>


> rpm --upgrade jre-7u18-linux-x64.rpm
> 

and you are finished, you don’t need to do anything else.

I forgot, there is one gotcha. The init script “/etc/init.d/jexec” has
an error, which you notice when you insert the script. It has this section:


### BEGIN INIT INFO
# Provides: binfmt_misc
# Required-Start: $local_fs
# Default-Start: 1 2 3 4 5
# Default-Start: 0 6
# chkconfig: 12345 95 05
# Description: Supports the direct execution of binary formats.
### END INIT INFO

should be this:


### BEGIN INIT INFO
# Provides: binfmt_misc
# Required-Start: $local_fs
# Required-Stop:
# Default-Start: 1 2 3 4 5
# Default-Stop: 0 6
# chkconfig: 12345 95 05
# Description: Supports the direct execution of binary formats.
### END INIT INFO


The “Required-Stop” is missing, and the second “Default-Start” is in
fact the “Default-Stop” section. This is a bug that has been there for
YEARS and Sun/Oracle has not bothered to correct. And it is an easy
one… one has to imagine what else that one does not know is hiding
somewhere.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

I have decided to create a script to correct the references:

me@host:~> cat /richi/Src/Scripts/java-env.sh
JAVA_HOME=/usr/local/jdk1.7.0_17
JRE_HOME=$JAVA_HOME/jre
JAVA_BINDIR=$JAVA_HOME/bin
SDK_HOME=$JAVA_HOME
JDK_HOME=$JAVA_HOME
JAVA_ROOT=$JAVA_HOME

And this is what I have in my environment after a

source /richi/Src/Scripts/java-env.sh
me@host:/richi/Src/Jpo> env | egrep -i "java|jdk|sdk"
JRE_HOME=/usr/local/jdk1.7.0_17/jre
JAVA_BINDIR=/usr/local/jdk1.7.0_17/bin
JAVA_HOME=/usr/local/jdk1.7.0_17
SDK_HOME=/usr/local/jdk1.7.0_17
JDK_HOME=/usr/local/jdk1.7.0_17
JAVA_ROOT=/usr/local/jdk1.7.0_17

Regards,
Richard

On 2013-03-24 19:36, richardeigenmann wrote:
> I have decided to create a script to correct the references:

Put it inside your local .profile file, that’s it purpose. Or create an
“/etc/profile.d/alljava.bash” file.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

Hi,
I found your thread while determining how I should install Java. I found a gazillion ways googling.

This link might help: Support | How to manually install Oracle Java into SLED 11 SP1/2
The last part says:

As some scripts expects JAVA_HOME variable, you can add the following the following lines to the file /etc/profile.d/zzz-oracle-java.sh:

export JAVA_HOME=/usr/java/latest
export JAVA_ROOT=/usr/java/latest
export JAVA_BINDIR=/usr/java/latest/bin
export JRE_HOME=/usr/java/latest

This is a bug discussion on alljava.sh here: Access Denied

It looks like you are on the right track.

Hi,

I did have some other comments and concerns, mostly about update-alternatives (UA). Is it needed at all? It seems the system could be kept as-is and set the variables for anything else. And Netbeans has its own options to add and remove java versions. But if you opt to change java for the system, how do you determine what files?

A handy bash way to look at the JAVA variables (the output can be used in your .bashrc w/appropriate file changes):

declare -p ${!J@}; declare -p ${!SD@}

Searching the net, I’ve seen many variations of UA. It varies from none, to just java and javac, to everything (java related) with/without slaves. One user just changed to the /usr/local/jdk1.7.0_17 directory and did a:

for f in *; do update-alternatives --install /usr/bin/$f $(pwd)/$f 40; done 

I looked at:


update-alternatives --get-selections

Took the results and looked for master names that were located in /usr/lib64, like java, javac, javaplugin, javadocdir, etc, and did (for each):


update-alternatives --query java

I thought I could construct a reasonable UA command with the above info. But does it really matter if they are slaves in a link group or just all master links. This is a manual install. The next release of java will be installed in its own directory and this process repeated. So the above command kind of makes sense. I think it isn’t complete though because it only hits the bin directory. It misses the man pages.

Thank you.

On 2013-03-26 07:56, opensuseforumorg42 wrote:
> This is a manual install. The next release of
> java will be installed in its own directory and this process repeated.

Nope.

If you use the java rpm for installation and upgrades, you do those
customizations just the first time.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

**3 step installation. **
In this case (an older version of suse), I’m leaving the system alone, so update-alternatives is not necessary.
I think for most desktop installations this would be sufficient.

  1. I downloaded java and netbeans combo from Java SE Downloads.
  2. Extracted and installed into /usr/local/jdk1.7.0_17
  3. And I set them in my .bashrc'. If I wanted them system-wide, I'd probably set something up in /etc/bash.bashrc.local’.

declare -x JAVA_HOME="/usr/local/jdk1.7.0_17"
declare -x JRE_HOME="${JAVA_HOME}/jre"
declare -x JAVA_BINDIR="${JAVA_HOME}/bin"
declare -x SDK_HOME="${JAVA_HOME}"
declare -x JDK_HOME="${JAVA_HOME}"
declare -x JAVA_ROOT="${JAVA_HOME}"
declare -x JAVA_MAN="${JAVA_HOME}/man"

alias netbeans='/usr/local/netbeans-7.3/bin/netbeans'
alias jvars='declare -p ${!J@}; declare -p ${!SD@}'

if  -d "${JAVA_BINDIR}" ]]; then
  # I want the java directory in second place. See man Bash, Parmeter Expansion.
  PATH="${PATH%%:*}":"${JAVA_BINDIR}":"${PATH#*:}"
fi

if  -d "${JAVA_MAN}" ]]; then
  MANPATH="${JAVA_MAN}":"${MANPATH}"
fi

The changes to alljava.sh (where the variables come from) seems to hard code: ‘/usr/lib64/jvm /usr/lib/jvm /usr/java/latest /usr/java’. From reading, it is my understanding that Oracle’s rpm uses the later directories, but that doesn’t seem to follow the FHS, Filesystem Hierarchy Standard. You still don’t need to touch /etc/alternatives, just update the environmental variables. I don’t think the original post included an update to $PATH. I hope this helped the originally poster too. Great thread. Thank you!!!

https://github.com/openSUSE/aaa_base/blob/master/files/etc/profile.d/alljava.sh

On 2013-03-26 22:46, opensuseforumorg42 wrote:

> 2. Extracted and installed into /usr/local/jdk1.7.0_17

Why don’t you simply download and install the rpm from the same site?

> 3. And I set them in my `.bashrc’. If I wanted them system-wide, I’d

probably set something up in `/etc/bash.bashrc.local’.

Nope, the correct file is “~/.profile” for home, or “/etc/profile.local”
for system wide. As explained in the bugzilla.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)