Gentoo Java Guide
1. What is Java?
Overview
Java is a programming language developed by engineers of Sun Microsystems.
The language is object-oriented and designed to run on multiple platforms
without the need of recompiling code for each platform. Although Java can
be compiled as a native program, much of Java's popularity can be attributed
to its portability, along with other features such as garbage collection.
The ability to compile once and run in various platforms is achieved through
the use of just-in-time compilers (JIT), which compile Java bytecodes into
native code when a given program is run.
In order to run Java bytecodes, one needs to have a JRE (Java Runtime Environment)
installed. A JRE provides core libraries, a platform dependent Java Virtual Machine,
plug-ins for browsers, among other things. A JDK (Java Development Kit) adds
programming tools, such as a bytecode compiler and a debugger.
2. Installing a JRE/JDK
The choices
Gentoo provides numerous JREs and JDKs. Among the current alternatives, we have:
- blackdown-jre and blackdown-jdk, the Blackdown Java Kit
- sun-jre-bin and sun-jdk, Sun's Java Kit
- ibm-jre-bin and ibm-jdk-bin, the IBM Java Kit
- compaq-jre and compaq-jdk, the Compaq Java Kit for Alpha/Linux/GNU
- jrockit-jdk-bin, BEA WebLogic's J2SE Development Kit
The default is the Blackdown JRE/JDK
pair, as it is freely ("free as in beer") available without any registration
fuss.
Both the Sun JRE/JDK and the IBM JRE/JDK 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 JRE/JDKs will notify you of where to go to
download them.
Installing the Sun/IBM JRE/JDKs
If you run emerge =sun-jdk-1.4.2.06 or =ibm-jdk-bin-1.4.2, you will
be notified that you are required to download the actual tarballs yourself. This
has to do with license restrictions for the Sun JRE/JDK (online click-wrap
license) and registration issues with the IBM JRE/JDK.
Note:
ibm-jdk-bin is currently masked, you may have to unmask it to use it.
|
You should download the indicated file(s) into
/usr/portage/distfiles. Once that is done, you can rerun the emerge
command, then the JRE/JDK will be installed properly into /opt.
3. Configuring your JRE/JDK
Overview
Gentoo has the ability to have multiple JDKs and JREs installed without them
conflicting.
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 JRE/JDK
Running the command java-config --list-available-vms will give you a list
of all available JREs and JDKs on your system. Here is an example of output:
Code Listing 3.1: Listing available VMs |
# java-config --list-available-vms
[blackdown-jdk-1.3.1] Blackdown JDK 1.3.1 (/etc/env.d/java/20blackdown-jdk-1.3.1)
[blackdown-jre-1.3.1] Blackdown JRE 1.3.1 (/etc/env.d/java/20blackdown-jre-1.3.1)
[ibm-jdk-1.3.0] IBM JDK 1.3.0 (/etc/env.d/java/20ibm-jdk-1.3.0)
[ibm-jdk-1.3.1] IBM JDK 1.3.1 (/etc/env.d/java/20ibm-jdk-1.3.1)
[ibm-jre-1.3.1] IBM JRE 1.3.1 (/etc/env.d/java/20ibm-jre-1.3.1)
[sun-jdk-1.4.0] Sun JDK 1.4.0 (/etc/env.d/java/20sun-jdk-1.4.0)
|
The name in the brackets "[]" is the handle or ID for that
particular VM. You use pass that ID to java-config --set-system-vm. Here is
an example of how to set the system VM.
Code Listing 3.2: Setting the System VM |
# java-config --set-system-vm ibm-jdk-1.3.1
Now using IBM JDK 1.3.1 (/etc/env.d/java/20ibm-jdk-1.3.1)
|
Note:
You will have to be root to run --set-system-vm.
|
Once you have issued java-config --set-system-vm with a particular VM
ID, you will need to regenerate your /etc/profile.env. You can do
it like this:
Code Listing 3.3: Regenerating /etc/profile.env |
# 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 ~/.gentoo/java-env with all required env vars. You would
normally source this from your shell's startup script (generally
~/.bashrc).
4. USE flags for use with Java
Setting USE flags
For more information regarding USE flags, refer to the USE flags
chapter from the Gentoo Handbook.
The flags
- The java flag adds support for Java in a variety of programs.
-
The nsplugin flag adds a symlink to the javaplugin for
Mozilla-like browsers (including Firefox) if you are using, for example,
Blackdown's Java kit, IBM Java Kit or Sun's Java Kit. You will need this
for viewing Java applets in your Mozilla-like browser.
5. Additional resources
Off-line resources
- java-config man page
- java-config --help
- The /usr/bin/java-config script itself
Online resources
The contents of this document are licensed under the Creative Commons -
Attribution / Share Alike license.
|