Difference between revisions of "Java"

From ArchWiki
Jump to: navigation, search
(minor enhancements, brought up to date)
(extended and restructured "Tips and Tricks", added some links)
Line 6: Line 6:
  
 
== Installation ==
 
== Installation ==
There are two Java Virtual Machines in the Arch repositories that can be installed on your system — the OpenJDK open source implementation and Oracle's (previously Sun's) closed source implementation. Arch recommends [http://openjdk.java.net/ OpenJDK]. Additional Java implementations are available via the [[AUR]].
+
There are two Java Virtual Machines in the Arch repositories that can be installed on your system — the [http://openjdk.java.net/ OpenJDK] open source implementation and Oracle's (previously Sun's) closed source implementation. Arch recommends OpenJDK. Additional Java implementations are available via the [[AUR]].
  
 
=== OpenJDK JVM ===
 
=== OpenJDK JVM ===
To be able to run Java programs, you can install {{Pkg|jre7-openjdk}} from the [[Official Repositories|official repositories]]. There are also a Java Development Kit in {{Pkg|jdk7-openjdk}}. Both JRE and JDK for ones, interested in previous version of Java (Java 6), can by found in {{Pkg|openjdk6}}.
+
To be able to run Java programs, you can install [[Wikipedia:JRE|Java runtime]] with package {{Pkg|jre7-openjdk}}, available in the [[official repositories]]. There are also a [[Wikipedia:JDK|Java Development Kit]] in {{Pkg|jdk7-openjdk}}. Both JRE and JDK for ones, interested in previous version of Java (Java 6), can by found in {{Pkg|openjdk6}}.
  
You will likely need the {{Pkg|icedtea-web}} package for Java functionality in browsers (applets and Web Start).
+
You will likely need the {{Pkg|icedtea-web}} package for Java functionality in browsers ([[Wikipedia:Java applet|applets]] and [[Wikipedia:Java Web Start|Web Start]]).
  
{{Note|If you experience any problems with the Java plug-in, you can try the solution suggested for the Firefox Flash plug-in: [[Flash#Plugins_are_installed_but_not_working]]. You can also try using non-free version, bundled with Oracle JRE.}}
+
{{Note|If you experience any problems with the Java plug-in, you can try the [[Flash#Plugins_are_installed_but_not_working|solution]], suggested for the Firefox Flash plug-in. You can also try using non-free version, bundled with Oracle JRE.}}
  
{{Note|If you use a non-reparenting window manager and Java 6, you should uncomment the corresponding line in {{Filename|/etc/profile.d/openjdk6.sh}}}}
+
{{Note|If you use a non-reparenting window manager and Java 6, you should uncomment the corresponding line in {{Ic|/etc/profile.d/openjdk6.sh}}}}
  
 
=== Oracle JVM ===
 
=== Oracle JVM ===
 
Prior to the [http://mailman.archlinux.org/pipermail/arch-general/2011-August/021671.html retirement of the Oracle DLJ], it was possible to simply install the {{Ic|jre}} and {{Ic|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 {{Ic|java-runtime}} and {{Ic|java-environment}}.
 
Prior to the [http://mailman.archlinux.org/pipermail/arch-general/2011-August/021671.html retirement of the Oracle DLJ], it was possible to simply install the {{Ic|jre}} and {{Ic|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 {{Ic|java-runtime}} and {{Ic|java-environment}}.
  
The [[AUR]] contains packages for {{AUR|jre}} and {{AUR|jdk}}, the Oracle implementations of Java.
+
AUR contains packages for {{AUR|jre}} and {{AUR|jdk}}, the Oracle implementations of Java.
  
{{Note|You will need to ensure that {{Filename|/opt/java/jre/bin/}} is in your {{Ic|$PATH}} variable, and that {{Ic|$JAVA_HOME}} points to the correct position (generally {{Filename|/opt/java}}). You can do this by either logging out and in again, or by sourcing {{Filename|/etc/profile}}.}}
+
{{Note|You will need to ensure that {{Ic|/opt/java/jre/bin/}} is in your {{Ic|$PATH}} variable, and that {{Ic|$JAVA_HOME}} points to the correct position (generally {{Ic|/opt/java}}). You can do this by either logging out and in again, or by sourcing {{Ic|/etc/profile}}.}}
  
 
=== Apache Harmony ===
 
=== Apache Harmony ===
Line 31: Line 31:
  
 
=== BEA JRockit JIT JVM (+JDK) ===
 
=== BEA JRockit JIT JVM (+JDK) ===
The JIT version of Java is available from the [[AUR]] here: {{AUR|jrockit}}.
+
[[Wikipedia:JRockit|JRockit]] is JIT version of Java, provided by Oracle and available from the AUR here: {{AUR|jrockit}}.
  
 
=== VMkit LLVM-based JIT VM ===
 
=== VMkit LLVM-based JIT VM ===
Line 37: Line 37:
  
 
=== Parrot VM ===
 
=== Parrot VM ===
The [http://www.archlinux.org/packages/?q=parrot Parrot VM] offers experimental [http://trac.parrot.org/parrot/wiki/Languages support for Java] through two different methods: Either as a [http://code.google.com/p/parrot-jvm/ Java VM bytecode translator] or as a [https://github.com/chrisdolan/perk Java compiler targeting the Parrot VM].
+
The [http://www.archlinux.org/packages/?q=parrot Parrot VM] offers experimental [http://trac.parrot.org/parrot/wiki/Languages support for Java] through two different methods: Either as a [http://code.google.com/p/parrot-jvm/ Java VM bytecode translator] or as a [https://github.com/chrisdolan/perk Java compiler targeting the Parrot VM]. Available in the AUR package {{AUR|parrot-git}}.
  
== Java sound with Pulseaudio ==
+
== 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#Enable remote access|MySQL article]].
 +
 
 +
=== Java sound with Pulseaudio ===
 
{{Note|This procedure is likely to be relevant for previous version of Java (Java 6) only.}}
 
{{Note|This procedure is likely to be relevant for previous version of Java (Java 6) only.}}
  
Line 46: Line 50:
 
(These paths are correct for Sun's Java, you will need to change the paths for OpenJDK)
 
(These paths are correct for Sun's Java, you will need to change the paths for OpenJDK)
  
First, rename the {{filename|java}} binary to {{filename|java.bin}}
+
First, rename the {{Ic|java}} binary to {{Ic|java.bin}}
 
  # mv /opt/java/jre/bin/java /opt/java/jre/bin/java.bin
 
  # mv /opt/java/jre/bin/java /opt/java/jre/bin/java.bin
Then, create a new launcher script at {{filename|/opt/java/jre/bin/java}}
+
Then, create a new launcher script at {{Ic|/opt/java/jre/bin/java}}
 
  #!/bin/sh
 
  #!/bin/sh
 
  padsp /opt/java/jre/bin/java.bin "$@"
 
  padsp /opt/java/jre/bin/java.bin "$@"
Line 57: Line 61:
 
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.
 
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.
  
==Additional notes==
+
== Tips and tricks ==
===MySQL===
+
{{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.}}
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 need to edit {{filename|/etc/mysql/my.cnf}} and comment out the line looking like this:
+
  skip-networking
+
  
[https://wiki.archlinux.org/index.php/MySQL Read the article about MySQL for more information.]
+
Behavior of most Java applications can be controlled by supplying predefined variables to Java runtime. From [https://bbs.archlinux.org/viewtopic.php?id=72892 this forum post], a way to do it consists of adding the following line in your {{Ic|~/.bashrc}} (or {{Ic|/etc/profile.d/jre.sh}} to affect all users):
  
===GTK LookAndFeel===
+
export _JAVA_OPTIONS="-D'''<option 1>''' -D'''<option 2>'''..."
If your java programs look ugly, you may want to set up the default look and feel for the swing components.
+
From [https://bbs.archlinux.org/viewtopic.php?id=72892 this forum post], a way to do it consists of adding the following line in your {{filename|~/.bashrc}} (or {{filename|/etc/profile.d/jre.sh}} to affect all users)
+
  
  export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
+
=== Better font rendering ===
 +
Both closed source and open source one implementations of Java are known to have improperly implement antialiasing of fonts. This can be fixed with following options: {{Ic|1=awt.useSystemAAFontSettings=on}}, {{Ic|1=swing.aatext=true}}
  
{{Note|{{Ic|awt.useSystemAAFontSettings}} is deprecated in Java 7}}
+
=== GTK LookAndFeel ===
 +
If your java programs look ugly, you may want to set up the default look and feel for the swing components: {{Ic|1=swing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel}}.

Revision as of 06:14, 29 January 2012

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

"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

There are two Java Virtual Machines in the Arch repositories that can be installed on your system — the OpenJDK open source implementation and Oracle's (previously Sun's) closed source implementation. Arch recommends OpenJDK. Additional Java implementations are available via the AUR.

OpenJDK JVM

To be able to run Java programs, you can install Java runtime with package jre7-openjdk, available in the official repositories. There are also a Java Development Kit in jdk7-openjdk. Both JRE and JDK for ones, interested in previous version of Java (Java 6), can by found in openjdk6.

You will likely need the icedtea-web package for Java functionality in browsers (applets and Web Start).

Note: If you experience any problems with the Java plug-in, you can try the solution, suggested for the Firefox Flash plug-in. You can also try using non-free version, bundled with Oracle JRE.
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.

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.

Parrot VM

The Parrot VM offers experimental support for Java through two different methods: Either as a Java VM bytecode translator or as a Java compiler targeting the Parrot VM. Available in the AUR package parrot-gitAUR.

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.

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 one implementations of Java are known to have improperly implement antialiasing of fonts. This can be fixed with 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.