Java/en

Java is Sun Microsystems, which uses a platform-independent virtual machine to execute Java bytecode in real-time.]] It is a popular choice for developers who want to create cross-platform business applications.

Overview
Java is a programming language developed by 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 automatic memory management. To make platform independence possible the Java compiler compiles the Java code to an intermediate representation called Java bytecode that runs on a JVM (Java Virtual Machine) and not directly on the operating system.

In order to run Java bytecode, one needs to have a JRE (Java Runtime Environment) installed. A JRE provides core libraries, a platform dependent JVM, plugins for browsers, among other things. A JDK (Java Development Kit) adds programming tools, such as a bytecode compiler and a debugger.

JVM languages
The Java virtual machine is not used exclusively by Java programming language. Multiple programming languages use the Java platform and run on the JVM. Examples of such include: Clojure, Apache Groovy, or.

The choices
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:

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 for the selected JRE flavor.

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:

Overview
Gentoo has the ability to have multiple JDKs and JREs installed without causing conflicts.

Setting a default
The command can be used to present a list of installed Java instances (be it JRE or JDK). Here is an example of the output:

The user-vm flag indicates the default JVM for the user. The system-vm flag indicates the default JVM for the system and the fallback if a user JVM is not set. The number in the brackets (i.e. [1]) is the reference for the particular JVM. To set the default system JVM:

To set a preferred user JVM:

Setting a default CLASSPATH
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, will create  file, which should be sourced from the '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
For those who need a Java-enabled browser for a specific use case, there is e.g. /  available in the   overlay, which has long-term support for NPAPI and thus Java plugins up to JDK 8.

Setting USE flags
For more information regarding s, refer to the USE flags chapter from the.

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;

Following USE flags go in JAVA_PKG_IUSE, see for details and other specific USE flags of Java:


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

Minecraft launcher errors

 * A specific error in which  crashed after a few seconds, throwing "Alarm" and "SaveToBuffer failed" error was solved by setting  the USE flag   for.


 * When executing  the following error was produced:

This was solved by executing  with the following option:

External resources

 * Configuring Java per directory with jEnv
 * 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: