Java/fr

Ce guide vous introduit à Java et vous explique comment l'utiliser avec 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 librairies du cœur, une machine virtuelle Java dépendante de la plateforme et des greffons 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 procure de nombreux environnement d'exécution (JREs) et kits de développement (JDKs). Dans les choix courants, nous trouvons :

Installer un JRE/JDK
Pour installer le JDK par défaut de votre profil, exécutez. Ou pour installer le JRE par défaut de votre profil, exécutez.

Quelques JDKs et JREs, y compris les paquets de Sun, nécessitent que l'utilisateur accepte un contrat de licence utilisateur final CLUF (en anglais End User License Agreement ou EULA). Si cette licence (telle que dlj-1.1) n'est pas listée dans la variable ACCEPT_LICENSE dans, vous ne serez pas en mesure d'installer le JDK/JRE. Pour savoir comment ajouter des licences acceptables à, reportez-vous au manuel de Portage.

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

Installer une machine virtuelle à recherche restreinte
Quelques JDKs et JREs vous obligent à faire quelques explorations avant l'installation. Installez (avec emerge) les paquets comme vous le feriez normalement. Les ebuilds vous indiqueront où aller et quoi télécharger.

Vous devriez télécharger les fichiers indiqués dans. Une fois ces fichiers en place, vous pouvez relancer la commande emerge qui commencera alors à installer le JRE/JDK.

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

En utilisant l'outil, vous pouvez définir la version par défaut applicable à tout le système  (à condition que vous ayez un accès super-utilisateur). Les utilisateurs peuvent également utiliser  pour définir leur propre version par défaut.

Setting a default virtual machine
Running the command  will give you a list of all JREs and JDKs installed on your system. Here is an example of output:

The * indicates this is the current active vm (system-vm or user-vm when set). The name in the brackets ([]) is the handle or ID for that particular VM. You use the handle or the number to. Here is an example of how to set the system VM.

Setting the system VM by handle (preferred):

You can also select it by number:

As a regular user, you can use.

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 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 your system or user VM is strongly discouraged as these VMs will then be used when running the executables and will also be used by any packages not using Gentoo's launcher scripts.

Preferred Build VM
While merging Java packages, the VM used for building can sometimes be different from the one currently set as the system VM.

This merge time VM switching is needed when, for example, your system-vm is set to a 1.6 VM and the package you are merging requires a 1.5 VM. While merging it will select and use a 1.5 VM, leaving your system-vm choice intact.

To define which VM is selected when a switch is needed, we have created a list of default/supported VMs per arch. You can find them in.

You can override these defaults (and even your selected system VM) in and have complete control over which VM will get used for merging.

For example, to always use a :

Or, always use  wherever possible, except for when a 1.4 or 1.3 VM is explicitly required:

Or to use different providers for different versions, such as requiring  if a 1.3 (yes, 1.3) VM is asked, and fall back to   otherwise:

Compilers
The standard Java compiler used for building is, which comes with each JDK. In addition to configuring the VM used at build time, it is also possible configure which compiler is used. Essentially, you define a list your preference for which compiler to use in.

Some compilers don't support all possible -target and -source arguments. Therefore, each compiler in the list is checked to see if it can support the desired -source/-target. javac will work in all cases, so if no other suitable compiler is found, it will be used instead.

More details about each compiler are provided below:

Setting a default CLASSPATH
can also be used to set a system-wide default CLASSPATH, as well a user-specific default CLASSPATH.

First, you will want to list available Java libraries installed on your system that might want to be put in your CLASSPATH. Here is an example of output:

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

You will have to update your environment by logging out, then in again or sourcing.

For users,  will create, which you should then source from your shell's profile.

Sourcing user specific classpath

If you really want a system wide or user default classpath you can add something like the following to your shell's profile. But we would advise against it.

Installing a plugin
You can install a Java plugin for your web browser by emerging a Java VM with the  USE flag set.

Portage will allow you to install multiple versions of Java plugins, though only one will be used by your browser. You can check the list of available plugins by running:

In this example,  is selected for the browser plugin.

Verify that the correct plugin was selected:

Java.com also provides a link to verify your installed plugin. Additionally, if you are using a Mozilla-based browser, you can verify your Java plugin by typing  into the address bar.

Plugins on multilib systems
If you are running a mixed 64-bit and 32-bit multilib system (for example, on AMD64), you can use 64-bit and 32-bit Java plugins. Unless you have a pressing need to run 32-bit Java applications, we recommend using native 64-bit plugins on 64-bit web browsers.

There are several native 64-bit browser plugins available. The default JDK/JRE pair,  and , both include browser plugins. Just emerge one of them with the  USE flag enabled.

To use a 32-bit plugin on a 32-bit browser, you will need to emerge  with the   USE flag enabled.

Next, check which plugins are available:

Now select the right plugin for your browsers:

Verify the correct plugin was selected:

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 support for Mozilla-like browsers (including Firefox). You will need this for viewing Java applets in your Mozilla-like browser.
 * The source flag installs a zip of the source code of a package. This is traditionally used for IDEs to 'attach' source to the libraries you are using.
 * The jce flag adds support for the Java Cryptography Engine
 * For Java packages, the doc flag will build API documentation using javadoc.

Off-line resources

 * java-config man page

Online resources

 * The Java Project Page
 * The gentoo-java, gentoo-user, and gentoo-dev mailing list archives
 * #gentoo and #gentoo-java on IRC
 * Wikipedia's entry for Java
 * If you have suggestions or questions regarding this document, please email the Gentoo Java team:

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide:


 * Joshua Nichols
 * Karl Trygve Kalleberg
 * Joshua Saddler