<?xml version="1.0" encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/java.xml,v 1.14 2005/03/06 12:08:19 swift Exp $ -->
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">

<guide link="/doc/en/java.xml">
<title>Gentoo Java Guide</title>

<author title="Author and Editor">
 <mail link="karltk@gentoo.org">Karl Trygve Kalleberg</mail>
</author>
<author title="Editor">
 <mail link="swift@gentoo.org">Sven Vermeulen</mail>
</author>
<author title="Editor">
 <mail link="marcelogoes@gmail.com">Marcelo Góes</mail>
</author>

<abstract>
This guide will introduce users and developers to Java and explain how to use
Java with Gentoo Linux.
</abstract>

<license/>

<version>0.1.6</version>
<date>2005-03-06</date>

<chapter>
<title>What is Java?</title>
<section>
<title>Overview</title>
<body>

<p>
Java is a programming language developed by engineers of Sun Microsystems.
The language is object-oriented and designed to run on multiple platforms
without the need of recompiling code for each platform. Although Java can
be compiled as a native program, much of Java's popularity can be attributed
to its portability, along with other features such as garbage collection.
The ability to compile once and run in various platforms is achieved through
the use of just-in-time compilers (JIT), which compile Java bytecodes into
native code when a given program is run.
</p>

<p>
In order to run Java bytecodes, one needs to have a JRE (Java Runtime Environment)
installed. A JRE provides core libraries, a platform dependent Java Virtual Machine, 
plug-ins for browsers, among other things. A JDK (Java Development Kit) adds
programming tools, such as a bytecode compiler and a debugger.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Installing a JRE/JDK</title>
<section>
<title>The choices</title>
<body>

<p>
Gentoo provides numerous JREs and JDKs. Among the current alternatives, we have:
</p>

<ul>
<li>blackdown-jre and blackdown-jdk, the Blackdown Java Kit</li>
<li>sun-jre-bin and sun-jdk, Sun's Java Kit </li>
<li>ibm-jre-bin and ibm-jdk-bin, the IBM Java Kit</li>
<li>compaq-jre and compaq-jdk, the Compaq Java Kit for Alpha/Linux/GNU</li>
<li>jrockit-jdk-bin, BEA WebLogic's J2SE Development Kit</li>
</ul>

<p>
The default is the Blackdown JRE/JDK
pair, as it is freely ("free as in beer") available without any registration 
fuss.
</p>

<p>
Both the Sun JRE/JDK and the IBM JRE/JDK are generally faster, but getting them
is a bit more work, as you are required to read and accept their license before
downloading (IBM additionally requires you to register).
</p>

<p>
Our ebuilds for the Sun and IBM JRE/JDKs will notify you of where to go to
download them.
</p>

</body>
</section>

<section>
<title>Installing the Sun/IBM JRE/JDKs</title>
<body>

<p>
If you run <c>emerge =sun-jdk-1.4.2.06</c> or <c>=ibm-jdk-bin-1.4.2</c>, you will
be notified that you are required to download the actual tarballs yourself. This
has to do with license restrictions for the Sun JRE/JDK (online click-wrap
license) and registration issues with the IBM JRE/JDK.
</p>

<note>
ibm-jdk-bin is currently masked, you may have to unmask it to use it.
</note>

<p>
You should download the indicated file(s) into
<path>/usr/portage/distfiles</path>. Once that is done, you can rerun the emerge
command, then the JRE/JDK will be installed properly into <path>/opt</path>.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Configuring your JRE/JDK</title>
<section>
<title>Overview</title>
<body>

<p>
Gentoo has the ability to have multiple JDKs and JREs installed without them
conflicting.
</p>

<p>
Using the <c>java-config</c> tool, you can set the system-wide default if you
have root access. Users can also use <c>java-config</c> to set up their own
personal default, that is different from the system-wide default.
</p>

</body>
</section>

<section>
<title>Setting a default JRE/JDK</title>
<body>

<p>
Running the command <c>java-config --list-available-vms</c> will give you a list
of all available JREs and JDKs on your system. Here is an example of output:
</p>

<pre caption="Listing available VMs">
# <i>java-config --list-available-vms</i>
[blackdown-jdk-1.3.1] Blackdown JDK 1.3.1 (/etc/env.d/java/20blackdown-jdk-1.3.1)
[blackdown-jre-1.3.1] Blackdown JRE 1.3.1 (/etc/env.d/java/20blackdown-jre-1.3.1)
[ibm-jdk-1.3.0] IBM JDK 1.3.0 (/etc/env.d/java/20ibm-jdk-1.3.0)
[ibm-jdk-1.3.1] IBM JDK 1.3.1 (/etc/env.d/java/20ibm-jdk-1.3.1)
[ibm-jre-1.3.1] IBM JRE 1.3.1 (/etc/env.d/java/20ibm-jre-1.3.1)
[sun-jdk-1.4.0] Sun JDK 1.4.0 (/etc/env.d/java/20sun-jdk-1.4.0)
</pre>

<p>
The name in the brackets <path>"[]"</path> is the handle or ID for that
particular VM. You use pass that ID to <c>java-config --set-system-vm</c>. Here is
an example of how to set the system VM.
</p>

<pre caption="Setting the System VM">
# <i>java-config --set-system-vm=ibm-jdk-1.3.1</i>
Now using IBM JDK 1.3.1 (/etc/env.d/java/20ibm-jdk-1.3.1)
</pre>

<note>
You will have to be root to run --set-system-vm.
</note>

<p>
Once you have issued <c>java-config --set-system-vm</c> with a particular VM ID,
you will need to regenerate your /etc/profile.env. You can do it like this:
</p>

<pre caption="Regenerating /etc/profile.env" >
# <i>env-update</i>
</pre>

<p>
After this, you will either want to relogin, or resource
<path>/etc/profile</path> into your environment.
</p>

<p>
As a regular user, you can use <c>java-config --set-user-vm</c>, which will
create <path>~/.gentoo/java-env</path> with all required env vars. You would
normally source this from your shell's startup script
(generally <path>~/.bashrc</path>).
</p>

</body>
</section>

<section>
<title>Setting a default CLASSPATH</title>
<body>

<p>
<c>java-config</c> can also be used to set a system-wide default CLASSPATH, and
of course a user-specific default CLASSPATH.
</p>

<p>
First you want to list available java libraries that might be interesting to put
in your CLASSPATH. Here is an example of output:
</p>

<pre caption="Listing classes">
# <i>java-config --list-available-packages</i>
[bsh] BeanShell is a small, free, embeddable, Java
source interpreter with object scripting language
features. (/usr/share/bsh/package.env)
[oro] A set of text-processing Java classes that
provide Perl5 compatible regular expressions, AWK-like
regular expressions, glob expressions, and utility
classes for performing substitutions, splits, filtering
filenames, etc. (/usr/share/oro/package.env)
[bcel] The Byte Code Engineering Library: analyze, create,
manipulate Java class files (/usr/share/bcel/package.env)
[jsch] JSch is a pure Java implementation of SSH2.
(/usr/share/jsch/package.env)
...
</pre>

<p>
Again, the name in brackets <path>"[]"</path> are the IDs that you have to pass
to <c>java-config --set-system-classpath</c>. Here is an example:
</p>

<pre caption="Setting classpaths">
# <i>java-config --set-system-classpath=log4j,java-gtk,java-gnome</i>
</pre>

<note>
The current directory (.) will not be part of the system classpath, as that
should be added in root's login profile.
</note>

<p>
Again, you will want to run <c>env-update</c> to update your system's
environment, and you might also want to relogin or resource the
<path>/etc/profile</path>.
</p>

<p>
For users, <c>java-config --set-user-classpath</c> will create
<path>~/.gentoo/java-env-classpath</path>, which is automatically included
by <path>~/.gentoo/java-env</path>.
</p>

</body>
</section>
</chapter>

<chapter>
<title>USE flags for use with Java</title>
<section>
<title>Setting USE flags</title>
<body>

<p>
For more information regarding USE flags, refer to the 
<uri link="/doc/en/handbook/handbook-x86.xml?part=2&amp;chap=2">USE flags</uri>
chapter from the Gentoo Handbook.
</p>

</body>
</section>
<section>
<title>The flags</title>
<body>

<ul>
<li>The <b>java</b> flag adds support for Java in a variety of programs.</li>
<li>The <b>mozilla</b> flag adds support for Mozilla-like browsers (including Firefox)
if you are using blackdown's Java kit. You will need this for viewing Java applets
in your Mozilla-like browser.</li>
</ul>

</body>
</section>
</chapter>

<chapter>
<title>Additional resources</title>
<section>
<title>Off-line resources</title>
<body>

<ul>
<li>java-config man page</li>
<li><c>java-config --help</c></li>
<li>The <path>/usr/bin/java-config</path> script itself</li>
</ul>

</body>
</section>

<section>
<title>Online resources</title>
<body>
<ul>
<li>The <uri link="http://news.gmane.org/gmane.linux.gentoo.devel"
>gentoo-dev</uri>, <uri link="http://news.gmane.org/gmane.linux.gentoo.user"
>gentoo-user </uri> mailing list archives</li>
<li>#gentoo and #gentoo-java on irc.freenode.net</li>
<li><uri link="http://en.wikipedia.org/wiki/Java_programming_language">Wikipedia's entry for Java</uri></li>
</ul>

</body>
</section>
</chapter>
</guide>
