Java/es

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

Visión general
Java es un lenguaje de programación desarrollado por ingenieros de Sun Microsystems. El lenguaje es totalmente orientado a objetos y diseñado para ser ejecutado en múltiples plataformas sin la necesidad de recompilar el código para cada una de ellas. Aunque Java puede ser compilado como un lenguaje nativo, mucha de la popularidad de Java se atribuye a su portabilidad, junto con otras características como recolección de basura. Para hacer posible esta independencia de plataforma, el compilador de Java compila el codigo Java hacia una representación intermedia denominada "Java bytecode" que es ejecutado en un JRE (Java Runtime Environment) y no directamente sobre el sistema operativo.

Para ejecutar Java bytecode, es necesario tener un entorno JRE (Java Runtime Environment) instalado. Un JRE proporciona bibliotecas centrales, una maquina virtual de Java dependiente de plataforma, y extensiones para navegadores web entre otras cosas. Por otro lado un JDK (Java Development Kit) agrega herramientas de programación, tales como compilador de bytecode y un depurador de codigo.

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

Instalando un JRE/JDK
To install the profile's default JDK run:

To install the profile's default JRE run:

Some JDKs and JREs, including the Sun 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.

Para evitar cualquier restricción de licencias, considérese instalar icedtea-bin, el cual es una implementación abierta de Java del proyecto OpenJDK.

Instalando maquinas virtuales con descarga restringida
Algunos JDKs y JREs necesitan unos pasos adicionales para realizar sus configuraciones. Hacer emerge de los paquetes tal y como se realiza normalmente. Si son necesarios pasos adicionales, los ebuilds ofrecerán instrucciones para los usuarios acerca de dónde ir y qué descargar.

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.

Configurar un JRE sin monitor ni teclado
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:

Visión general
Gentoo posee la habilidad de instalar multiples JDKs y JREs sin causar conflictos.

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.

Estableciendo una maquina virtual por defecto
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.

Estableciendo la maquina virtual manualmente (modo preferido):

Método alternativo: seleccionar la máquina virtual por número:

Como usuario normal, utilizar java-config.

Maquina virtual marcada como Build Only
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.

Maquina virtual preferida para compilación
Al instalar paquetes Java, la máquina virtual utilizada puede ser diferente de la configurada actualmente como máquina virtual del sistema.

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

To define which VM is selected when a switch is needed, a list of default/supported VMs per arch has been created. It can be found in.

These defaults can be over written (even the selected system VM) in for complete control over which VM will get used for merging.

For example, to always use a sun-jdk:

Or, to always use sun-jdk-1.5 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 ibm-jdk-bin otherwise:

Compiladores
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, define a list with preference for which compiler to use in.

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

Más detalles acerca de los compiladores son descritos a seguir:

Estableciendo un CLASSPATH por defecto
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:

Instalando un complemento
Es posible instalar complementos Java para navegadores web haciendo emerge de una máquina virtual Java con el ajuste USE  habilitado.

Portage will allow installations of multiple Java plugins versions, though only one will be used by the web browser. Check the list of available plugins by running:

In this example, is selected for the browser plugin.

Luego, se verifica si el complemento correcto fue seleccionado:

Java.com also provides a link to verify the installed plugin. Additionally, if a Mozilla-based browser is being used, verification of the Java plugin can be performed by typing into the address bar.

Complementos en sistemas multilib
If running a mixed 64-bit and 32-bit multilib system (for example, on ), use both 64-bit and 32-bit Java plugins. Unless there is a pressing need to run 32-bit Java applications, users have been recommended to use 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  USE enabled.

To use a 32-bit plugin on a 32-bit browser, the package will need to be emerged with   USE enabled.

Luego, deben verificarse cuales complementos están disponibles:

Now select the right plugin for the browser:

Por ultimo, debe verificarse que el complemento correcto haya sido seleccionado:

Establecer los ajustes 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.

Ver también

 * The Java User Guide in the Java project

Recursos externos

 * 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:



Para aportar sugerencias o realizar preguntas acerca de este documento, por favor envíe un mensaje de correo electrónico al equipo Java de Gentoo: