Gentoo provides numerous JDKs and JREs. The default is the
Blackdown JDK/JRE pair, as it is freely (beer) available without any
registration fuss.

As kaffe becomes a JRE/JDK drop-in replacement, that will most
likely become our default.

Both the Sun JDK/JRE and the IBM JDK/JRE are generally faster, but
getting them is a bit more work, as you are required to read and
accept their license before downloading (IBM additionally requires you
to register).

Our ebuilds for the Sun and IBM JDK/JREs will notify you of where
to go to download them.

Installing the Sun/IBM JDK/JREs

If you run emerge sun-jdk-1.3.1 or emerge
ibm-jdk-1.3.1, you will be notified that you are required
to download the actual tarballs yourself. This has to do with license
restrictions for the Sun JDK/JRE (online click-wrap license) and
registration issues with the IBM JDK/JRE.

There is also a sun-jdk-1.4.0, but not all packages
work nicely with Java 1.4, so you're on your own if you use the 1.4.0
JDK.

You should download the indicated file(s) into
/usr/portage/distfiles. Once that is done, you can rerun
the emerge command, then the JDK/JRE will be installed properly into
/opt.

Configuring your JDK/JREOverview

Gentoo has the ability to have multiple JDKs and JREs installed
without them conflicting. There are a few caveats to this, as noted
below.

Using the java-config tool, you can set the system-wide
default if you have root access. Users can also use java-config
to set up their own personal default, that is different from the
system-wide default.

Setting a default JDK/JRE

Running the command java-config --list-available-vms will
give you a list of all availble JREs and JDKs on your system, thus:

Once you have issued java-config --set-system-vm with a
particular VM ID, you will need to regenerate your /etc/profile.env,
thus:

[#1 ~] env-update

After this, you will either want to relogin, or resource
/etc/profile into your environment.

As a regular user, you can use java-config --set-user-vm,
which will create $HOME/.gentoo/java-env with all
required env vars. You would normally source this from your shell's
startup script ($HOME/.zshenv in my case).

Setting a default CLASSPATH

java-config can also be used to set a system-wide default
CLASSPATH, and of course a user-specific default CLASSPATH.

First you want to list available java libraries that might be
interesting to put in your CLASSPATH, thus:

None of these packages have a proper description. That is
something that will be implemented in the not-so-distant
future.

Again, the name in brackets "[]" are the IDs that you
have to pass to java-config --set-system-classpath, thus:

java-config --set-system-classpath=log4j,java-gtk,java-gnome

The current directory (.) will not be part of the system classpath,
as that should be added in root's login profile.

Again, you will want to run env-update to update your
system's environment, and you might also want to relogin or resource
the /etc/profile.

For users, java-config --set-user-classpath will create
$HOME/.gentoo/java-env-classpath, which is automatically
included by $HOME/.gentoo/java-env.

Additional resourcesOff-line resources

java-config man page

java-config --help

The /usr/bin/java-config script itself

Online resources

The
gentoo-dev ,
gentoo-user
mailing list archives

#gentoo on irc.openprojects.net

CaveatsGeneral

If you select a JRE as your default VM, you may not have a
javac command handy at all times, unless you have manually
installed a symlink to take care of that.

Jikes will be used to compile some of the largest packages, if it
is available. With time, we hope to be able to compile all
java-dependent packages with Jikes, so some dependencies on the JDK
can be replaced with a dependency on the JRE.

With some versions of Portage, doing an emerge --world
update will install the JDK regardless if whether you have it
installed before or not. This is a known bug addressed in later
versions of Portage.