Re: Configuring Java in Suse 11.1 Linux
Roedy Green wrote:
On Mon, 6 Jul 2009 21:03:41 -0700 (PDT), piscesboy
<oraclmaster@gmail.com> wrote, quoted or indirectly quoted someone who
said :
I updated my JDK to 1.6 in Suse Linux 11.1 and it can't compile even
the simplest of programs.
To check that my default java is correctly set, I ran:
/usr/sbin/update-alternatives --display java
and got:
java - status is auto.
link currently points to /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
followed by a bunch of alternative java installs.
It is set to choose the "best" JDK for the job which is jre-1.6.0-
openjdk/bin/java
Now even the following simple code won't compile properly:
import java.io.*;
public class Hello{
public static void main(String[] args){
System.out.println("It works.");
}
}
when I compile using javac Hello.java.
Every time, it says "undefined reference to 'main'.
Am I invoking it wrong?
First, I advise uninstalling all javas in the universe, JDKs and JREs.
Then prune any left over directories. You are just torturing yourself
if you have more than one Java installed at a time.
Not at all. Any number of JDK/JRE can happily co-exist in Linux. That may not be
so in the Windows world, but it is certainly so in the Linux/UNIX world.
I am pretty sure that YaST (the openSUSE package manager) supports the
co-existence of at least one version of OpenJDK and the Sun JDK/JRE.
Installation of a newer version or either will cause RPM to upgrade the
installed version. These different Java releases can be switched using the
alternatives mechanism.
Further to this it is perfectly possible to have any number of Sun Java versions
by downloading and installing the binary self-installers (not the RPM versions)
direct from the Sun website.
For example, on my RedHat desktop system (which is very similar to openSUSE in
package management) I have:
java-1.6.0-sun-devel-1.6.0.14-1jpp.1.el5.i586.rpm
the JPP packaged Java from Sun, included in RedHat
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115:
the gcj Java implementation, which is used by some core components of RedHat
and can't be removed without removing half the OS.
java-1.6.0-openjdk-devel-1.6.0.0-0.30.b09.el5
the latest OpenJDK, just in case I want to test it.
All the above are managed by the RedHat installer and controlled by
alternatives:
# alternatives --config java
There are 3 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/lib/jvm/jre-1.6.0-sun/bin/java
2 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
3 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
The Sun Java is currently the default version which will be used by the
commands 'java', 'javac' etc. But I can easily switch between any of the 3
installed flavours of Java.
Plus I have these other versions, downloaded from Sun:
j2sdk1.4.2_06
jdk1.5.0_09
jdk1.6.0_01
jdk1.6.0_06
jdk1.6.0_10
jdk-6u2-fcs-src (this is just the source, if I want to see how a standard class
is implemented).
I can access these by running the specific java/javac executable, e.g.
jdk1.6.0_06/bin/java would run that release JVM.
Then reboot and install your Java. Make sure it is JDK, not a JRE3.
An OS should not need re-booting just because you've [un]installed a user-land
application (and this generally applies to Windows as well, although it's
perfectly possible for a badly written Windows installer to require it).
After you have it installed. check a few things
java.exe -version should display the expected version of the runtime.
java
It will display "java.exe: command not found"
There is no java.exe in a Linux install.
javac.exe -version should display the expected version of the
compiler.
It won't, see above.
rt.jar should exist somewhere in the Java directory tree.
I have not used SUSE,
It shows.
but as I recall the install for Ubuntu has some
tricky unintuitive steps to it. Make sure you read the instructions.
Don't just follow your nose.
Search for references to setting up JAVA_HOME
Not necessary. I can use any of the above versions of Java I have installed
without any hint of a JAVA_HOME, CLASSPATH or any other environment variable.
In fact, all they do is confuse the issue and make it more difficult to support
more than a single version of Java. Maybe this is why you torture yourself when
you try to install more than one version of Java simultaneously.
The java/javac commands determine what path they were executed from, and will
use the appropriate rt.jar/JRE from that path provided you don't confuse them
with environment variables.
See the instructions at http://mindprod.com/jgloss/jdk.html
on testing your JDK. They are for windows, but some advice may also
apply to you.
--
Nigel Wade