Java/ko

이 안내서는 독자 여러분께 자바 언어를 소개하고 젠투 리눅스에서 자바를 활용하는 방법을 설명합니다.

간단히 살펴보기
자바는 썬 마이크로시스템즈의 엔지니어가 개발한 프로그래밍 언어입니다. 언어는 객체지향이며 각각의 플랫폼에서 코드를 다시 컴파일하지 않아도 여러 플랫폼에서 동작하도록 설계했습니다. 비록 자바를 네이티브 프로그램처럼 컴파일 할 수 있지만 대부분의 자바 배포 프로그램은, 가비지 콜렉션과 같은 기능을 붙여가며 이식성을 부여할 수 있습니다. 플랫폼은 독립적으로 자바 컴파일러가 운영체제가 아닌 JRE(자바 런타임 환경)에서 실행할 "자바 바이트 코드"라고 하는 중간 형태의 자바 코드로 컴파일 할 수 있습니다.

자바 바이트 코드를 실행하려면 JRE(자바 런타임 환경)을 설치해야합니다. JRE는 핵심 라이브러리, 플랫폼과 별개로 동작하는 자바 가상 머신, 브라우저 플러그인, 등을 제공합니다. JDK(자바 개발 키트)는 바이트 코드 컴파일러 및 디버거와 같은 프로그래밍 도구를 추가합니다.

선택
젠투는 다양한 런타임 환경(JRE)과 개발 키트(JDK)를 제공합니다. 현재 선택할 수 있는 방안은 다음과 같습니다:

JRE/JDK 설치
To install the profile's default JDK run emerge virtual/jdk. Or run emerge virtual/jre to install the profile's default JRE.

Some JDKs and JREs, including the Sun packages, require accepting an End User License Agreement, or EULA. If its license (such as dlj-1.1) is not listed in the  variable (found in ), then  the JDK/JRE will be unable to be installed. For more information on how to add acceptable licenses to read the Licenses chapter of the Portage Handbook.

To avoid any restrictive license hassle, consider installing icedtea-bin, which is an open Java implementation from the OpenJDK project.

Installing fetch-restricted virtual machines
Some of the JDKs and JREs require a few extra steps in their configurations. Emerge the packages as normal. If additional steps are required the ebuilds will provide instruction for the user on where to go and what to download.

Download the indicated file(s) into Once the files are in the right directories, rerun the emerge command, at which point the JRE/JDK will be begin to install.

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 3 USE flags need to be unset.

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:

Overview
Gentoo has the ability to have multiple JDKs and JREs installed without causing conflicts.

Using the java-config tool with root privileges, a system-wide default java virtual machine (VM) can be set. Users can also use java-config to custom set their personal VM on a user-by-user basis.

Setting a default virtual machine
Running the java-config --list-available-vms command will output a list of all JREs and JDKs installed on the system. Here is an example of the output:

The * indicates this is the current active JVM (system-vm or user-vm when set). The name in the brackets ([]) is the handle or ID for that particular VM. The handle or the number to java-config --set-system-vm can be used to set the VM. The following text provides an example of how to set the system VM.

Setting the system VM by handle (preferred):

Alternate method: select VM by number handle number:

As a regular user, use java-config.

Build Only VM
Some virtual machines are flagged as build-only due to being EOL and/or containing security vulnerabilities. These virtual machines will not automatically be used by Gentoo for the running of applications using Gentoo launchers (run-java-tool script designed for switching VMs), but will still be available for use by Gentoo's build environment as some packages may require them for building. The setting of these virtual machines as either the system or user VM is strongly discouraged as these VMs will then be used when running the executables, as well as used by any packages not using Gentoo's launcher scripts.

Preferred Build VM
While merging Java packages, the VM used for building can sometimes be different from the one currently set as the system VM.

This merge time VM switching is needed when, for example, the system-vm is set to a 1.6 VM and the package being merge requires a 1.5 VM. While merging it will select and use a 1.5 VM, leaving the system-vm choice intact.

To define which VM is selected when a switch is needed, a list of default/supported VMs per arch has been created. It can be found in.

These defaults can be over written (even the selected system VM) in for complete control over which VM will get used for merging.

For example, to always use a sun-jdk:

Or, to always use sun-jdk-1.5 wherever possible, except for when a 1.4 or 1.3 VM is explicitly required:

Or to use different providers for different versions, such as requiring  if a 1.3 (yes, 1.3) VM is asked, and fall back to ibm-jdk-bin otherwise:

Compilers
The standard Java compiler used for building is javac, which comes with each JDK. In addition to configuring the VM used at build time, it is also possible configure which compiler is used. Essentially, define a list with preference for which compiler to use in.

Some compilers do not support all possible  and   arguments. Therefore, each compiler in the list is checked to see if it can support the desired /. javac will work in all cases, so if no other suitable compiler is found, it will be used instead.

More details about each compiler are provided below:

Setting a default CLASSPATH
java-config can also be used to set a system-wide default CLASSPATH, as well a user-specific default CLASSPATH.

First, list available Java libraries installed on the system to possibly put in the  variable. Here is an example of output:

Again, the names in brackets ([]) are the IDs to pass to java-config --set-system-classpath. Here is an example:

Update the environment by logging out, then in again or by typing source.

For users, java-config --set-user-classpath will create, which should then source from the shell's profile.

If desiring a system wide or user default classpath add something like the following to the shell's profile. This is advised against:

Installing a plugin
It is possible to install a Java plugins for a web browsers by emerging a Java VM with the  USE flag set.

Portage will allow installations of multiple Java plugins versions, though only one will be used by the web browser. Check the list of available plugins by running:

In this example, sun-jre-bin is selected for the browser plugin.

Verify that the correct plugin was selected:

Java.com also provides a link to verify the installed plugin. Additionally, if a Mozilla-based browser is being used, verification of the Java plugin can be performed by typing about:plugins into the address bar.

Plugins on multilib systems
If running a mixed 64-bit and 32-bit multilib system (for example, on AMD64), use both 64-bit and 32-bit Java plugins. Unless there is a pressing need to run 32-bit Java applications, users have been recommended to use native 64-bit plugins on 64-bit web browsers.

There are several native 64-bit browser plugins available. The default JDK/JRE pair,  and , both include browser plugins. Just emerge one of them with  USE enabled.

To use a 32-bit plugin on a 32-bit browser, the package will need to be emerged with   USE enabled.

Next, check which plugins are available:

Now select the right plugin for the browser:

Verify the correct plugin was selected:

Setting USE flags
For more information regarding USE flags, refer to the USE flags chapter from the Gentoo Handbook.

The USE flags

 * The  flag adds support for Java in a variety of programs;
 * The  flag adds support for Mozilla-like browsers (including Firefox). This is needed for viewing Java applets in a Mozilla-like browser;
 * The  flag installs a zip of the source code of a package. This is traditionally used for IDEs to 'attach' source to the libraries that are being use;
 * The  flag adds support for the Java Cryptography Engine;
 * For Java packages, the  flag will build API documentation using javadoc.

External resources

 * The gentoo-java, gentoo-user, and gentoo-dev mailing list archives
 * #gentoo and #gentoo-java on IRC
 * Wikipedia's entry for Java
 * Java 7 and bootstrapping icedtea on the Gentoo forums

More information can be found offline:
 * man java-config
 * java-config --help

For suggestions or questions regarding this document, please email the Gentoo Java team: