"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." — Wikipedia article

Installation

The only JVM implementation in supported repositories is the open source OpenJDK. Additional Java implementations are available via the AUR. Keep in mind that the open-source and closed-source versions cannot be installed simultaneously. The open-source version is nearly perfect at the time of writing, and there is mostly no need anymore to install Oracle's proprietary version of Java.

Note: If you use a non-reparenting window manager and Java 6, you should uncomment the corresponding line in /etc/profile.d/openjdk6.sh

Oracle JVM

Prior to the retirement of the Oracle DLJ, it was possible to simply install the jre and jdk packages from the repositories. However, now Arch Linux (and any other GNU/Linux distribution) can no longer package the Oracle implementation of Java. The OpenJDK packages are the recommended providers of java-runtime and java-environment.

AUR contains packages for jreAUR and jdkAUR, the Oracle implementations of Java.

Note: You will need to ensure that /opt/java/jre/bin/ is in your $PATH variable, and that $JAVA_HOME points to the correct position (generally /opt/java). You can do this by either logging out and in again, or by sourcing /etc/profile.

Oracle JVM (Java 6)

Seeing as how jreAUR and jdkAUR have been updated to Java SE 7, the installation of Java SE 6, the older reference implementation of Java can't be installed through the AUR. However, it can be installed manually. To do so, consult the article Java SE 6 for instructions on how to do so manually.

Apache Harmony

Apache Harmony is a clean room re-implementation of the Java language and comes under the Free Apache license. A binary re-distribution of the Harmony JRE can be found in the AUR: apache-harmony-jreAUR.

Kaffe

Kaffe is another clean-room implementation of a Java VM without official endorsement from Sun/Oracle. A git package of Kaffe can be found in the AUR here: kaffe-gitAUR. The Kaffe VM is redistributed according to the GPL license.

BEA JRockit JIT JVM (+JDK)

JRockit is JIT version of Java, provided by Oracle and available from the AUR here: jrockitAUR.

VMkit LLVM-based JIT VM

VMkit is an LLVM-based framework for JIT virtual machines. J3 is a JVM running on VMkit. A broken build for VMkit can be found in the AUR here: vmkit-svnAUR. J3 depends on the GNU classpath libraries, but may also work with the Apache class path libraries.

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 instructions in MySQL article.

Java sound with Pulseaudio

Note: This procedure is likely to be relevant for previous version of Java (Java 6) only.

By default, Java and Pulseaudio do not get along very well with each other, but this is easy to fix using padsp.

(These paths are correct for Sun's Java, you will need to change the paths for OpenJDK)

First, rename the java binary to java.bin

# mv /opt/java/jre/bin/java /opt/java/jre/bin/java.bin

Then, create a new launcher script at /opt/java/jre/bin/java

#!/bin/sh
padsp /opt/java/jre/bin/java.bin "$@"

Finally, make the launcher script executable

# chmod +x /opt/java/jre/bin/java

You will need to redo this process on each update of Java.

You can also try replacing padsp with aoss, which can also fix it under standard ALSA as well as in Pulse, do what works best. I must warn everyone that these hacks sometimes work perfect, but are sometimes very unstable as well.

Impersonate Another Window Manager

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

$ 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, many users prefer to impersonate “LG3D,” the non-re-parenting window manager written by Sun, in Java.

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/jre.sh to affect all users):

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

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: awt.useSystemAAFontSettings=on, swing.aatext=true

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.