From ArchWiki
Revision as of 09:45, 1 October 2017 by Wget (talk | contribs) (→‎Installation: Add notes about OpenJFX)
Jump to navigation Jump to search

From the Wikipedia article:

Java is a programming language originally developed by Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture.

Arch Linux officially supports the open source OpenJDK versions 7, 8, and 9. All these JVM can be installed without conflict and switched between using helper script archlinux-java. Several other Java environments are available in AUR but are not officially supported.


  • Installing a JDK will automatically pull its JRE dependency.
  • After installation, the Java environment will need to be recognized by the shell ($PATH variable). This can be done by sourcing /etc/profile from the command line or by logging out/in again of a Desktop Environment.

Two common packages are respectively pulled as dependency, named java-runtime-common (containing common files for Java Runtime Environments) and java-environment-common (containing common files for Java Development Kits). The provided environment file /etc/profile.d/ points to a linked location /usr/lib/jvm/default/bin, set by the archlinux-java helper script. The links /usr/lib/jvm/default and /usr/lib/jvm/default-runtime should always be edited with archlinux-java. This is used to display and point to a working default Java environment in /usr/lib/jvm/java-${JAVA_MAJOR_VERSION}-${VENDOR_NAME} or a Java runtime in /usr/lib/jvm/java-${JAVA_MAJOR_VERSION}-${VENDOR_NAME}/jre.

Most executables of the Java installation are provided by direct links in /usr/bin, while others are available in $PATH.

Warning: File /etc/profile.d/ is not provided any more by any package.

The following packages are available:

OpenJDK 7 — The open-source implementation of the seventh edition of Java SE. || jre7-openjdk-headless jre7-openjdk jdk7-openjdk openjdk7-doc openjdk7-src

OpenJDK 8 — The open-source implementation of the eight edition of Java SE. || jre8-openjdk-headless jre8-openjdk jdk8-openjdk openjdk8-doc openjdk8-src

OpenJFX 8 — The open-source implementation of JavaFX. You do not need to install this package if you are making use of Java SE (the Oracle's implementation of JRE and JDK described below). This package only concerns users of the open source implementation of Java (OpenJDK project). || java-openjfx java-openjfx-doc java-openjfx-src

OpenJDK 9 — The open-source implementation of the ninth edition of Java SE. || jre9-openjdk-headless jre9-openjdk jdk9-openjdk openjdk9-doc openjdk9-src

Java SE — Oracle's implementation of JRE and JDK. || jreAUR jre6AUR jre7AUR jre8AUR jre-develAUR jdkAUR jdk5AUR jdk6AUR jdk7AUR jdk8AUR jdk-develAUR

Parrot VM — a VM with experimental support for Java [1] through two different methods: either as a Java VM bytecode translator, or as a Java compiler targeting the Parrot VM. || parrot
Note: 32-bit versions of Java SE can be found by prefixing bin32-, e.g. bin32-jreAUR and bin32-jdkAUR. They use java32-runtime-commonAUR, which functions as java-runtime-common by suffixing with 32, e.g. java32.

Flagging packages as out-of-date

Although the Arch Linux package releases may contain a reference to the proprietary versions the packages are based on, the open-source project has its own versioning scheme:

Switching between JVM

The helper script archlinux-java provides such functionalities:

archlinux-java <COMMAND>

	status		List installed Java environments and enabled one
	get		Return the short name of the Java environment set as default
	set <JAVA_ENV>	Force <JAVA_ENV> as default
	unset		Unset current default Java environment
	fix		Fix an invalid/broken default Java environment configuration

List compatible Java environments installed

$ archlinux-java status


$ archlinux-java status
Available Java environments:
  java-7-openjdk (default)

Note the (default) denoting that java-7-openjdk is currently set as default. Invocation of java and other binaries will rely on this Java install. Also note on the previous output that only the JRE part of OpenJDK 8 is installed here.

Change default Java environment

# archlinux-java set <JAVA_ENV_NAME>


# archlinux-java set java-8-openjdk/jre
Tip: To see possible <JAVA_ENV_NAME> names, use archlinux-java status.

Note that archlinux-java will not let you set an invalid Java environment. In the previous example, jre8-openjdk is installed but jdk8-openjdk is not so trying to set java-8-openjdk will fail:

# archlinux-java set java-8-openjdk
'/usr/lib/jvm/java-8-openjdk' is not a valid Java environment path

Unsetting the default Java environment

There should be no need to unset a Java environment as packages providing them should take care of this. Still should you want to do so, just use command unset:

# archlinux-java unset

Fixing the default Java environment

If an invalid Java environment link is set, calling the archlinux-java fix command tries to fix these. Also note that if no default Java environment is set, this will look for valid ones and try to set it for you. Officially supported packages "OpenJDK 7" and "OpenJDK 8" will be considered first in this order, then un-official packages from AUR.

# archlinux-java fix

Launching an application with the non-default java version

If you want to launch an application with another version of java than the default one (for example if you have both version jre7 and jre8 installed on your system), you can wrap your application in a small bash script to locally change the default PATH of java. For example if the default version is jre7 and you want use jre8:


export PATH=/usr/lib/jvm/java-8-openjdk/jre/bin/:$PATH
exec /path/to/application "$@"

Package pre-requisites to support archlinux-java

This section is targeted at packager willing to provide packages in AUR for an alternate JVM and be able to integrate with Arch Linux JVM scheme to use archlinux-java. To do so, packages should:

Also please note that:

  • Packages that need any Java environment should declare dependency on java-runtime, java-runtime-headless or java-environment as usual
  • Packages that need a specific Java vendor should declare dependency on the corresponding package
  • OpenJDK packages now declare provides="java-runtime-openjdk=${pkgver}" etc. This enables a third-party package to declare dependency on an OpenJDK without specifying a version



Due to the fact that the JDBC-drivers often use the port in the URL to establish a connection to the database, it is considered "remote" (i.e., MySQL does not listen to the port as per its default settings) despite the fact that they are possibly running on the same host, Thus, to use JDBC and MySQL you should enable remote access to MySQL, following the instructions in MySQL#Grant remote access.

Impersonate another window manager

You may use the wmname from to make the JVM believe you are running a different window manager. This may solve a rendering issue of Java GUIs occurring in window managers like Awesome or Dwm or Ratpoison.

$ wmname LG3D

You must restart the application in question after issuing the wmname command.

This works because the JVM contains a hard-coded list of known, non-re-parenting window managers. For maximum irony, some users prefer to impersonate LG3D, the non-re-parenting window manager written by Sun, in Java.

Illegible fonts

In addition to the suggestions mentioned below in #Better font rendering, some fonts may still not be legible afterwards. If this is the case, there is a good chance Microsoft fonts are being used. Install ttf-ms-fontsAUR from the AUR.

Missing text in some applications

If some applications are completely missing texts it may help to use the options under #Tips and tricks as suggested in FS#40871.

Applications not resizing with WM, menus immediately closing

The standard Java GUI toolkit has a hard-coded list of "non-reparenting" window managers. If using one that is not on that list, there can be some problems with running some Java applications. One of the most common problems is "gray blobs", when the Java application renders as a plain gray box instead of rendering the GUI. Another one might be menus responding to your click, but closing immediately.

There are several things that may help:

  • For jre7-openjdk or jre8-openjdk, append the line export _JAVA_AWT_WM_NONREPARENTING=1 in /etc/profile.d/ Then, source the file /etc/profile.d/ or log out and log back in.
  • For Oracle's JRE/JDK, use SetWMName. However, its effect may be canceled when also using XMonad.Hooks.EwmhDesktops. In this case, appending
>> setWMName "LG3D"

to the LogHook may help.

See [2] for more information.

System freezes when debugging JavaFX Applications

If your system freezes while debugging a JavaFX Application, you can try to supply the JVM option -Dsun.awt.disablegrab=true.


Tips and tricks

Note: Suggestions in this section are applicable to all applications, using explicitly installed (external) Java runtime. Some applications are bundled with own (private) runtime or use own mechanics for GUI, font rendering, etc., so none of written below is guaranteed to work.

Behavior of most Java applications can be controlled by supplying predefined variables to Java runtime. From this forum post, a way to do it consists of adding the following line in your ~/.bashrc (or /etc/profile.d/ to affect programs that are not run by sourcing ~/.bashrc, e.g., launching a program from Gnome's Applications view):

export _JAVA_OPTIONS="-D<option 1> -D<option 2>..."

For example, to use system anti-aliased fonts and make swing use the GTK look and feel:

export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true'

Better font rendering

Both closed source and open source implementations of Java are known to have improperly implemented anti-aliasing of fonts. This can be fixed with the following options: -Dawt.useSystemAAFontSettings=on, -Dswing.aatext=true

See Java Runtime Environment fonts for more detailed information.

Silence 'Picked up _JAVA_OPTIONS' message on command line

Setting the _JAVA_OPTIONS environment variables makes java (openjdk) write to stderr messages of the form: 'Picked up _JAVA_OPTIONS=...'. To supress those mesages in your terminal you can unset the environment variable in your shell startup files and alias java to pass those same options as command line arguments:

alias java='java "$_SILENT_JAVA_OPTIONS"'

GTK LookAndFeel

If your Java programs look ugly, you may want to set up the default look and feel for the swing components:

Some Java programs insist on using the cross platform Metal look and feel. In some of these cases you can force these apps to use the GTK look and feel by setting the following property:

Note: Forcing Java to use GTK may break some applications. The JRE/JDK is linked against GTK2 while many desktop applications use GTK3. If a GTK3 app has Java plugins with GUI, the app is likely to crash when opening the Java GUI, as mixing GTK2 and GTK3 in the same process is not supported. Libreoffice 5.0 is an example of this.

Better 2D performance

Switching to OpenGL-based hardware acceleration pipeline will improve 2D performance

export _JAVA_OPTIONS='-Dsun.java2d.opengl=true'

Non-reparenting window managers

Non-reparenting window managers user should set the following environment variable in their .xinitrc


See also