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.
|The IcedTea Open Java SE (formerly icedtea6-bin)
|The GCJ IcedTea GNU GCC Java (currently IcedTea-7)
| The IcedTea Open Java SE (formerly icedtea6-bin) | and |-
| OpenJDK | and |-
| Eclipse Temurin | |-
emerge --ask virtual/jdk
emerge --ask virtual/jre
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.
dev-java/icedtea headless-awt -alsa -cups
dev-java/icedtea-bin headless-awt -alsa -cups
dev-java/openjdk headless-awt -alsa -cups
dev-java/openjdk-bin headless-awt -alsa -cups
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 emerge in pretend mode:
emerge --pretend --verbose virtual/jre
配置 Java 虚拟机
Gentoo has the ability to have multiple JDKs and JREs installed without causing conflicts.
The eselect 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 following VMs are available for generation-2: * IcedTea JDK 220.127.116.11 [icedtea-7] * IcedTea JDK 3.0.1 [icedtea-8]
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. ) is the reference for the particular JVM. To set the default system JVM:
eselect java-vm set system 1
eselect java-vm set user 1
source-ing the profile for existing shell sessions is not usually needed when changing the user or system VM. The only exception is that variables such as JAVA_HOME will still point to the old location after setting a user VM for the first time or revert back to the system VM.
The Java plugin support had been deprecated in JDK 9.
For those who need a Java-enabled browser for a specific use case, there is e.g.
palemoon-bin available in the
palemoon overlay, which has long-term support for NPAPI and thus Java plugins up to JDK 8.
使用 Java 的 USE 标记
设置 USE 标签
Following USE flags go in JAVA_PKG_IUSE, see Gentoo Java USE flags for details and other specific USE flags of Java:
Minecraft launcher errors
- A specific error in which
minecraft-launchercrashed after a few seconds, throwing "Alarm" and "SaveToBuffer failed" error was solved by setting the USE flag
- When executing
minecraft-launcherthe following error was produced:
[0229/184549.183275:ERROR:sandbox_linux.cc(346)] InitializeSandbox() called with multiple threads in process gpu-process.
This was solved by executing
minecraft-launcher with the following option:
- man java-config
- java-config --help
This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: Joshua Nichols, Karl Trygve Kalleberg, nightmorph
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.