Java

Arch Linux officially supports the open source OpenJDK versions 8, 11, 17 and 19. 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.

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.

Installation

Note:
  • Arch Linux officially only supports the OpenJDK implementation.
  • 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 the Desktop Environment or reboot.

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/jre.sh points to a linked location /usr/lib/jvm/default/bin, set by the archlinux-java helper script.

Warning: 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 or a Java runtime in .

Most executables of the Java installation are provided by direct links in , while others are available in . The script /etc/profile.d/jdk.sh is no longer provided by any package.

OpenJDK

OpenJDK is an open-source implementation of the Java Platform, Standard Edition (Java SE), designated as the official reference implementation. There are several distributors of OpenJDK builds such as Adoptium (formerly known as AdoptOpenJDK) and Amazon Corretto. The Arch Linux OpenJDK packages are built from the upstream OpenJDK source code.

Headless JRE
The minimal Java runtime - needed for executing non-GUI Java programs.
Full JRE
Full Java runtime environment - needed for executing Java GUI programs, depends on headless JRE.
JDK
Java Development Kit - needed for Java development, depends on full JRE.
VersionHeadless JREFull JREJDKDocumentationSources
OpenJDK 19jre-openjdk-headless
OpenJDK 17openjdk17-src
OpenJDK 11jdk11-openjdk
OpenJDK 8

OpenJDK GA Latest OpenJDK General-Availability Release build from Oracle.

https://jdk.java.net || java-openjdk-binAUR

OpenJFX

OpenJFX is the open-source implementation of JavaFX. You do not need to install this package if you are using Oracle JDK. This package only concerns users of the open source implementation of Java (OpenJDK project), and its derivatives.

VersionRuntime and DevelopementDocumentationSources
OpenJFX 19
OpenJFX 17
OpenJFX 11java11-openjfxjava11-openjfx-src
OpenJFX 8

Other implementations

  • OpenJ9 Eclipse's implementation of JRE/JDK, based on the J9 JVM, contributed by IBM.
https://www.eclipse.org/openj9/ || jdk-openj9-binAUR jdk17-openj9-binAUR jdk11-openj9-binAUR jdk8-openj9-binAUR
  • Azul Zulu Azul's open source JDK implementations.
https://www.azul.com/downloads/ || zulu-8-binAUR zulu-10-binAUR zulu-11-binAUR zulu-12-binAUR zulu-13-binAUR zulu-14-binAUR zulu-15-binAUR zulu-16-binAUR zulu-17-binAUR zulu-18-binAUR zulu-19-binAUR

Development tools

For integrated development environments, see List of applications#Integrated development environments and the Java IDEs subsection specifically.

To discourage reverse engineering an obfuscator like can be used.

Decompilers

  • Java Decompiler (JD-Core) Popular Java decompiler providing a GUI (see JD-GUI) and supporting Java 1-10.
https://java-decompiler.github.io/ || jd-core-javaAUR

GUI Frontends

  • Bytecode Viewer Java reverse engineering suite, including a decompiler, editor and debugger; Frontend for CFR/Fernflower/Procyon
https://bytecodeviewer.com || bytecode-viewerAUR

Switching between JVM

The helper script archlinux-java provides such functionalities:

archlinux-java <COMMAND>

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

Example:

Note the (default) denoting that is currently set as default. Invocation of 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>

Example:

# 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, is installed but is not so trying to set will fail:

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 :

# archlinux-java unset

Fixing the default Java environment

If an invalid Java environment link is set, calling the command tries to fix it. 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 package "OpenJDK 8" will be considered first in this order, then other installed environments.

# 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 18 and 11 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 java 18 and you want to use java 11:

#!/bin/sh

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

For a systemd service you can append to environment variables in the drop-in file:

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, or as usual
  • Packages that need a specific Java vendor should declare dependency on the corresponding package
  • OpenJDK packages now declare etc. This enables a third-party package to declare dependency on an OpenJDK without specifying a version

Troubleshooting

MySQL

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 MariaDB#Grant remote access.

IntelliJ IDEA

If IntelliJ IDEA outputs with the system Java SDK path, you may have to install a different JDK package and select it as IDEA's JDK.

Impersonate another window manager

You may use the from suckless.org 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. 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 , the non-re-parenting window manager written by Sun, in Java. Try setting "compiz", "Metacity" or "LG3D".

$ wmname window_manager_name

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

Alternatively, the javaagent JavaMatePatch, created to set the WM name in MATE and resolve the bug with java swing apps working incorrectly when launched in full screen, can be used. Add -javaagent:JavaMatePatch-1.0.0-SNAPSHOT.jar=window_manager_name to the java options to use it.

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 .

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 .

Gray window, 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:

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

See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6714678

JavaFX's MediaPlayer constructor throws an exception

Creating instance of MediaPlayer class from JavaFX's sound modules might throw following exception (both Oracle JDK and OpenJDK)

... (i.e. FXMLLoader construction exceptions) ...
Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
 at javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
 at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:511)
 at javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:414)
 at <constructor call>
...

which is a result of some incompatibilities of JavaFX with modern build delivered within Arch Linux repository.

Working solution is to install .

See https://www.reddit.com/r/archlinux/comments/70o8o6/using_a_javafx_mediaplayer_in_arch/

If a Java application is not able to open a link to, for example, your web browser, install gvfs. This is required by the Desktop.Action.BROWSE method. See

Error initializing QuantumRenderer: no suitable pipeline found

Possible issues / solutions:

  • GTK2 is missing. Install
  • OpenJFX is missing. Install

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 (or /etc/profile.d/jre.sh to affect programs that are not run by sourcing ):

export JDK_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 JDK_JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel'

Three such variables exist, the options which are explained later in the table below take priority.

JAVA_TOOL_OPTIONS Affects applications as well as tools like javac or the jshell.
JDK_JAVA_OPTIONS Affects applications (everything started via the java command). Requires Java 9.
(command line options) Arguments specified before the "class name" argument are Java options.
_JAVA_OPTIONS The old way, affects applications and tools.

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

See Java Runtime Environment fonts for more detailed information.

Silence 'Picked up JDK_JAVA_OPTIONS' message on command line

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

SILENT_JAVA_OPTIONS="$JDK_JAVA_OPTIONS"
unset JDK_JAVA_OPTIONS
alias java='java "$SILENT_JAVA_OPTIONS"'

Non interactive shells, like the launcher scripts for Java programs, (usually) do not read the , but still inherited exported variables from their parent process (which in turn inherited it at some point from the login shell which read the ). As for the cases when they do, one put’s generally a statement at the op of the to avoid the file being read. That way, the variables are passed to programs launched via the desktop menu and in the case of an interactive shell where the message would disturb aliases are used instead (which in turn cannot be used in scripts).

GTK LookAndFeel

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

swing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel

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

swing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel

GTK3 Support

In Java releases prior to version 9, the GTK LookAndFeel is linked against GTK2, whilst many newer desktop applications use GTK3. This incompatibility between GTK versions may break applications utilizing Java plugins with GUI, as the mixing of GTK2 and GTK3 in the same process is not supported (for example, LibreOffice 5.0).

The GTK LookAndFeel can be run against GTK versions , and , defaulting to GTK3. This can be overridden by setting the following property:

jdk.gtk.version=2.2

HiDPI

Depending on the GUI framework, HiDPI#Java applications can be enabled using different methods.

Better 2D performance

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

export JDK_JAVA_OPTIONS='-Dsun.java2d.opengl=true'
gollark: ¿!?!?⸘
gollark: Also, should I PURCHASE™️ or CONSIDER PURCHASING™️™️ Terraria
gollark: Ah, but the numbers are going up and bigger numbers → more funner.
gollark: But when they do things, it helps *everyone*, including all other players!
gollark: No trading is permitted - people are assigned horses and stuff according to need, and if you go adventuring and get magic items they are cut into 500 pieces and sent to all adventurers nearby.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.