Java/fr

This guide introduces the reader to Java and explains how to use Java with Gentoo Linux.

Vue d'ensemble
Java est un langage de programmation qui a été développé par les ingénieurs de Sun Microsystems. C'est un langage orienté objet et conçu pour être exécuté sur des plateformes multiples sans avoir à recompiler le code pour chacune des plateformes. Bien que Java puisse être compilé comme un programme natif, la popularité de Java est essentiellement attribuable à sa portabilité, et à d'autres fonctionnalités comme la fonction éboueur. Pour rendre possible l'indépendance de la plateforme, le compilateur Java compile le code en une représentation intermédiaire appelée Java bytecode qui tourne sur un environnement d'exécution Java ou JRE et pas directement sur le système d'exploitation.

Afin d'exécuter le Java bytecode, il faut avoir un environnement d'exécution Java (Java Run Time Environment ou JRE) installé. Le JRE procure, parmi d'autres, les bibliothèques du cœur, une machine virtuelle Java dépendante de la plateforme et des modules d'extension pour les navigateurs. Un kit de développement Java (Java Development Kit ou JDK) ajoute des outils de programmation comme un compilateur de bytecote et un débogueur.

Les choix possibles
Gentoo provides numerous Java Runtime Environments (JREs) and Java Development Kits (JDKs). The current choices include:

Installing a JRE/JDK
To install the profile's default JDK run:

To install the profile's default JRE run:

Some JDKs and JREs, including the Oracle packages, require accepting an End User License Agreement, or EULA. If its license (such as dlj-1.1) is not listed in the ACCEPT_LICENSE variable (found in ), then the JDK/JRE will be unable to be installed. For more information on how to add acceptable licenses to read the Licenses chapter of the Portage Handbook.

Pour éviter le désagrément d'une licence trop restrictive, installez plutôt icedtea-bin, qui est une mise en œuvre libre de Java du projet OpenJDK.

Installing IcedTea GCJ Virtual Machine
The Icedtea virtual machine is provided in source code and requires compilation by a Java bytecode compiler. This bootstrapping can be executed by the GNU Compiler for Java (GCJ). This compiler is available when GCC is built with the  USE flag.

When GCC is rebuild with this USE flag set, the package can be installed:

Installer une machine virtuelle en limitant les recherches
Quelques JDKs et JREs vous obligent à passer par quelques étapes supplémentaires  pour leur configuration. Installez (avec emerge) les paquets comme vous le feriez normalement. Si des étapes supplémentaires sont nécessaires, les ebuilds vous indiqueront où aller et quoi télécharger.

Download the indicated file(s) into Once the files are in the right directories, rerun the  command, at which point the JRE/JDK will be begin to install.

Setting up a headless JRE
Sometimes there is no need for a full JRE with all the capabilities of java. Using java on a server often does not require any GUI, graphical, sound or even printer related features. To install a simplified (sometimes also referred to as headless) JRE, a few USE flags need to be changed.

Depending on the current Gentoo profile, this might already be the case. As usual, the USE flag settings that are applicable to a particular package can be checked by running in pretend mode:

Vue d'ensemble
Gentoo a la capacité à avoir plusieurs JDKs et JREs installés sans que cela ne crée de conflit.

Using the tool with root privileges, a system-wide default java virtual machine (VM) can be set. Users can also use java-config to custom set their personal VM on a user-by-user basis.

Définir une machine virtuelle par défaut
Running the command with the   option will output a list of all JREs and JDKs installed on the system. Here is an example of the output:

The * indicates this is the current active JVM (system-vm or user-vm when set). The name in the brackets ([]) is the handle or ID for that particular VM. The handle or the number to can be used to set the VM. The following text provides an example of how to set the system VM.

Définir la machine virtuelle système à l'aide de la poignée (solution préférée):

Alternate method: select VM by number handle number:

As a regular user, use java-config.

Build only VM
Some virtual machines are flagged as build-only due to being EOL and/or containing security vulnerabilities. These virtual machines will not automatically be used by Gentoo for the running of applications using Gentoo launchers (run-java-tool script designed for switching VMs), but will still be available for use by Gentoo's build environment as some packages may require them for building. The setting of these virtual machines as either the system or user VM is strongly discouraged as these VMs will then be used when running the executables, as well as used by any packages not using Gentoo's launcher scripts.

Configurer un CLASSPATH par défaut
can also be used to set a system-wide default CLASSPATH, as well a user-specific default CLASSPATH.

First, list available Java libraries installed on the system to possibly put in the CLASSPATH variable. Here is an example of output:

Again, the names in brackets ([]) are the IDs to pass to. Here is an example:

Update the environment by logging out, then in again or by typing

For users, java-config --set-user-classpath will create, which should then source from the shell's profile.

If desiring a system wide or user default classpath add something like the following to the shell's profile. This is advised against:

Java browser plugins
The Java browser plugin used to be managed via. This has now been removed in favor of a simpler out-of-the-box experience. For basic usage, simply emerge the chosen JVM with the  USE flag enabled. Note that Oracle's plugin is only available for and.

Also note that Chromium-based browsers no longer support NPAPI-based plugins since the code was removed in September 2015. The list of supporting browsers is shrinking but still includes Firefox as of version 46.

For more information, including JVM selection, Web Start, and multilib, see the README installed with icedtea-web.

Configurer les options de la variable USE
For more information regarding USE flags, refer to the USE flags chapter from the Gentoo Handbook.

USE flags

 * The flag adds support for Java in a variety of programs;
 * The flag adds support for Mozilla-like browsers (including Firefox). This is needed for viewing Java applets in a Mozilla-like browser;
 * The flag adds support for the Java Cryptography Engine;

Following USE flags go in JAVA_PKG_IUSE.
 * The flag installs a zip of the source code of a package. This is traditionally used for IDEs to 'attach' source to the libraries that are being use;
 * For Java packages, the flag will build API documentation using javadoc.

External resources

 * The gentoo-java, gentoo-user, and gentoo-dev mailing list archives
 * and on IRC
 * Java 7 and bootstrapping icedtea on the Gentoo forums

More information can be found offline:



For suggestions or questions regarding this document, please email the Gentoo Java team: