old-www/HOWTO/Enterprise-Java-for-Linux-H...

509 lines
17 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE>Enterprise Java for Linux HOWTO: How to Setup the Java Development Kit </TITLE>
<LINK HREF="Enterprise-Java-for-Linux-HOWTO-3.html" REL=next>
<LINK HREF="Enterprise-Java-for-Linux-HOWTO-1.html" REL=previous>
<LINK HREF="Enterprise-Java-for-Linux-HOWTO.html#toc2" REL=contents>
</HEAD>
<BODY>
<A HREF="Enterprise-Java-for-Linux-HOWTO-3.html">Next</A>
<A HREF="Enterprise-Java-for-Linux-HOWTO-1.html">Previous</A>
<A HREF="Enterprise-Java-for-Linux-HOWTO.html#toc2">Contents</A>
<HR>
<H2><A NAME="sec: jdk"></A> <A NAME="s2">2. How to Setup the Java Development Kit </A></H2>
<P>
<P>There are several Java Development Kits available for Linux. These include:
<P>
<UL>
<LI>
<A HREF="#sec: blackdown">Blackdown JDK</A></LI>
<LI>
<A HREF="#sec: ibmjdk">IBM Java Developer Kit </A></LI>
<LI>
<A HREF="#sec: j2se">Sun J2SE </A></LI>
<LI>
<A HREF="#sec: kaffe">Kaffe </A></LI>
</UL>
<P>If you are going to try just one JDK, I suggest you initially try the Sun
J2SE, unless you are recommended otherwise by specific software you are using
or want to use. Additionally, if you are interested in an open source implementation,
you will need to use Kaffe.
<H2><A NAME="sec: blackdown"></A> <A NAME="ss2.1">2.1 Blackdown JDK </A>
</H2>
<P>
<H3>Background </H3>
<P>
<P>The Blackdown JDK is a port of Sun JDK to Linux. As of the time of this
writing, the Blackdown JDK is current with JDK 1.2.2 on the Intel architecture
and 1.1.8 on the PowerPC.
<P>In December 1999, Sun announced availability of the Java 2 Platform, Standard
Endition (J2SE) on Linux. This Sun release has significant impact on Blackdown
because Blackdown is a port. In a press release, Sun states, &quot;This week's
announcement would not have been possible without the collaboration of Blackdown,
a group of developers and enthusiasts around the globe. Since its inception,
Blackdown has been a provider of Java technology for the Linux platform. Their
dedicated effort over a number of years has laid the foundation for this release
of the Java 2 platform port to Linux; in particular their effort was critical
to the success of this release.&quot;
<P>Additionally, the Sun press release continues, &quot;Blackdown.org continues
to be a valuable source for Java technology for Linux, including JDK 1.1.x
releases.&quot;
<H3>Download </H3>
<P>
<P>The Blackdown JDK can be obtained from
<A HREF="http://www.blackdown.org">http://www.blackdown.org</A>.
<P>>From the Blackdown home page, select download and a mirror site.
<P>Select the version of the JDK you want. If other software that you are
wanting to use does not recommend a specific version, I suggest the most current,
which is at the time of this writing, JDK 1.2.2.
<P>Select the machine architecture you are installing on. For Intel architecture,
select i386.
<P>Select the release candidate you want. If other software that you are
wanting to use does not recommend a specific release candidate, I suggest the
most recent or final version if available.
<P>For the Blackdown JDK, there are possibly a number of different files available
in different packaging formats. Additionally you have to be sure you get support
for the right libc for your Linux distribution.
<P>The files available include:
<UL>
<LI><EM>jdk</EM> - The Java Development Kit contains everything you need to compile,
run, and debug Java. It does not contain international character converters.
</LI>
<LI><EM>jre</EM> - The Java Runtime Environment, including international character converters.
</LI>
<LI><EM>rt</EM> - A minimal Java Runtime Environment that does not include international
character converters. </LI>
<LI><EM>i18n</EM> - The internationalization font mappings and a JAR containing the
international character converters. </LI>
<LI><EM>native</EM> - Additional binaries providing native thread support. </LI>
</UL>
<P>I suggest downloading only the jdk for Java development in English.
<P>When downloading the Blackdown files, you may need to select between libc5
and glibc as well as potentially a specific version of glibc. The libc options
include:
<UL>
<LI>libc5 - The older, and still most common, Linux libc is libc5. </LI>
<LI>glibc - The new Linux libc. </LI>
</UL>
<P>If you are using a newer distribution of Linux, you will most likely have
glibc. I suggest initially trying glibc.
<H3>Installation </H3>
<P>
<P>I suggest installing files in the /usr/local directory. After downloading
the files, run:
<PRE>
mkdir /usr/local/blackdown
mv jdk* /usr/local/blackdown
</PRE>
<P>If you downloaded the tarball format, run:
<PRE>
tar zxvf [filename].tar.gz
</PRE>
<P>Where [filename] is the name of the file.
<P>Under the /usr/local/blackdown directory, you now should see a directory
such as jdk1.2.2.
<P>The above example shows JDK 1.2.2 release candidate 3 for the Intel architecture.
Substitute the file name, version number, release candidate number, and architecture
as appropriate. You will need to open each distribution package file in the
above manner.
<H3>Setting up Your Environment </H3>
<P>
<P>The environment variables to set up are:
<UL>
<LI>JAVA_HOME</LI>
<LI>PATH</LI>
<LI>CLASSPATH</LI>
</UL>
<P>The JAVA_HOME environment variable references the home directory of your
JDK installation. Set your JAVA_HOME environment variable to the directory
into which you just installed a version of the Blackdown JDK.
<PRE>
export JAVA_HOME=/usr/local/blackdown/jdk1.2.2
</PRE>
<P>The $JAVA_HOME/bin directory has the Java compiler (javac) and the
Java Virtual Machine (java) as well as other necessary programs for development.
Add $JAVA_HOME/bin to your PATH.
<PRE>
export PATH=$JAVA_HOME/bin:$PATH
</PRE>
<P>Note that $JAVA_HOME/bin was added to the front of the PATH so that
the installed JDK will be used rather than any JDK that might have come with
your Linux distribution.
<P>To confirm that your PATH is correctly set up, check which Java compiler
and JVM will be used.
<PRE>
which javac
which java
</PRE>
<P>The output should reference javac and java in your $JAVA_HOME/bin
directory.
<P>The CLASSPATH environment variable references all JARs and directories
that you will need to compile and run Java programs.
<P>For JDK 1.2.2, you don't need to initially add any JARs to your CLASSPATH.
JARs can be packaged in either .jar or .zip files.
<PRE>
export CLASSPATH=$CLASSPATH:.
</PRE>
<H3>Confirming Your Installation </H3>
<P>
<P>You are now ready to compile and run a simple application. Create the
following program.
<PRE>
class HelloWorld {
public static void main (String[] args) {
System.out.println(&quot;Hello, World!&quot;);
}
}
</PRE>
<P>Compile the program with the Java compiler.
<PRE>
javac HelloWorld.java
</PRE>
<P>If the compiler produces errors, double check the syntax and confirm your
PATH and CLASSPATH.
<P>Run the program with the JVM.
<PRE>
java HelloWorld
</PRE>
<P>If the JVM produces errors, confirm your PATH and CLASSPATH.
<P>You should see the following output:
<PRE>
Hello, World!
</PRE>
<P>Congratulations, you have installed, set up an environment for, and tested
the Blackdown JDK on Linux.
<H3>More Information </H3>
<P>
<P>For more information on the Blackdown JDK, see the Blackdown website at
<A HREF="http://www.blackdown.org">http://www.blackdown.org</A>.
There is an excellent FAQ available.
<H2><A NAME="sec: ibmjdk"></A> <A NAME="ss2.2">2.2 IBM Java Developer Kit </A>
</H2>
<P>
<H3>Background </H3>
<P>
<P>The IBM Java Developer Kit and Runtime Environment pass Sun's Java compatibility
test and include the latest maintenance. (From the IBM website.)
<P>As of the time of this writing, the IBM Java Developer Kit is current with
JDK 1.1.8 and is available only on the Intel architecture.
<H3>Download </H3>
<P>
<P>The IBM Java Developer Kit can be obtained from
<A HREF="http://www.ibm.com/java/jdk/118/linux">http://www.ibm.com/java/jdk/118/linux</A>.
<P>
<P>In order to download, you will have to register with the IBM website and
agree to the license online.
<P>The files available include:
<UL>
<LI><EM>ibm-jdk-l118-linux-x86.tgz</EM> - The Java Development Kit contains everything
you need to compile, run, and debug Java. </LI>
<LI><EM>ibm-jre-l118-linux-x86.tgz</EM> - The Java Runtime Environment contains everything
you need to run Java. </LI>
</UL>
<P>Since you will be doing Java development, I suggest downloading the ibm-jdk
tarball file.
<H3>Installation </H3>
<P>
<P>I suggest installing files in the /usr/local directory. After downloading
the files, run:
<PRE>
mkdir /usr/local/ibm
mv ibm-jdk-l118-linux-x86.tgz /usr/local/ibm
</PRE>
<P>You can now open the distribution package. To do this, type:
<PRE>
tar zxvf ibm-jdk-l118-linux-x86.tgz
</PRE>
<P>Under the /usr/local/ibm directory, you now should see the jdk118 directory.
<P>
<P>The above example shows JDK 1.1.8 for the Intel architecture. Substitute
the filenames as appropriate.
<H3>Setting up Your Environment </H3>
<P>
<P>The environment variables to set up are:
<UL>
<LI>JAVA_HOME </LI>
<LI>PATH </LI>
<LI>CLASSPATH </LI>
</UL>
<P>The JAVA_HOME environment variable references the home directory of your
JDK installation. Set your JAVA_HOME environment variable to the directory
into which you just installed a version of the IBM Java Developer Kit.
<PRE>
export JAVA_HOME=/usr/local/ibm/jdk118
</PRE>
<P>The $JAVA_HOME/bin directory has the Java compiler (javac) and the
Java Virtual Machine (java) as well as other necessary programs for development.
Add $JAVA_HOME/bin to your PATH.
<PRE>
export PATH=$JAVA_HOME/bin:$PATH
</PRE>
<P>Note that $JAVA_HOME/bin was added to the front of the PATH so that
the installed JDK will be used rather than any JDK that might have come with
your Linux distribution.
<P>To confirm that your PATH is correctly set up, check which Java compiler
and JVM will be used.
<PRE>
which javac
which java
</PRE>
<P>The output should reference javac and java in your $JAVA_HOME/bin
directory.
<P>The CLASSPATH environment variable references all JARs and directories
that you will need to compile and run Java programs.
<P>Initially I suggest adding the following JARs to your CLASSPATH. JARs can
be packaged in either .jar or .zip files.
<P>For instance:
<PRE>
export CLASSPATH=$JAVA_HOME/lib/classes.zip
export CLASSPATH=$CLASSPATH:.
</PRE>
<H3>Confirming Your Installation </H3>
<P>
<P>You are now ready to compile and run a simple application. Create the
following program.
<PRE>
class HelloWorld {
public static void main (String[] args) {
System.out.println(&quot;Hello, World!&quot;);
}
}
</PRE>
<P>Compile the program with the Java compiler.
<PRE>
javac HelloWorld.java
</PRE>
<P>If the compiler produces errors, double check the syntax and confirm your
PATH and CLASSPATH.
<P>Run the program with the JVM.
<PRE>
java HelloWorld
</PRE>
<P>If the JVM produces errors, confirm your PATH and CLASSPATH.
<P>You should see the following output:
<PRE>
Hello, World!
</PRE>
<P>Congratulations, you have installed, set up an environment for, and tested
the IBM Java Developer Kit on Linux.
<H3>More Information </H3>
<P>
<P>For more information on the IBM Java Developer Kit, see the IBM Java website
at
<A HREF="http://www.ibm.com/java">http://www.ibm.com/java</A>.
<P>
<H2><A NAME="sec: kaffe"></A> <A NAME="ss2.3">2.3 Kaffe</A>
</H2>
<P>
<H3>Background</H3>
<P>
<P>Kaffe is a cleanroom, open source implmentation of a Java Virtual Machine
and class libraries. As of the time of this writing, Kaffe &quot;mostly complies
with JDK 1.1, except for a few missing parts.&quot; And &quot;parts of it
are already JDK 1.2 (Java 2) compatible.&quot; (From the Kaffe website.)
<P>
<P>Kaffe may have already been shipped with your Linux distribution because
of its open source license.
<H3>Download and Installation</H3>
<P>
<P>Rather than downloading from Kaffe, I suggest you initially try the Kaffe
that most likely came with your Linux distribution.
<P>Alternatively, Kaffe can be obtained from
<A HREF="http://www.kaffe.org">http://www.kaffe.org</A>.
<P>>From the Kaffe home page, select the current release. At the time of this
writing, the current release is 1.0.5. The Kaffe version number has no relationship
to JDK specification version numbers.
<H3>Setting up Your Environment </H3>
<P>
<P>The environment variables to set up are:
<UL>
<LI>PATH </LI>
<LI>CLASSPATH </LI>
</UL>
<P>To confirm that your PATH is correctly set up, check which Java compiler
and JVM will be used.
<PRE>
which javac
which java
</PRE>
<P>The CLASSPATH environment variable references all JARs and directories
that you will need to compile and run Java programs.
<P>Initially I suggest you add the following JARs to your CLASSPATH. JARs
can be packaged in either .jar or .zip files.
<P>For instance:
<PRE>
export CLASSPATH=/usr/local/share/kaffe/Klasses.zip
export CLASSPATH=$CLASSPATH:.
</PRE>
<H3>Confirming Your Installation </H3>
<P>
<P>You are now ready to compile and run a simple application. Create the
following program.
<PRE>
class HelloWorld {
public static void main (String[] args) {
System.out.println(&quot;Hello, World!&quot;);
}
}
</PRE>
<P>Compile the program with the Java compiler.
<PRE>
javac HelloWorld.java
</PRE>
<P>If the compiler produces errors, double check the syntax and confirm your
PATH and CLASSPATH.
<P>Run the program with the JVM.
<PRE>
java HelloWorld
</PRE>
<P>If the JVM produces errors, confirm your PATH and CLASSPATH.
<P>You should see the following output:
<PRE>
Hello, World!
</PRE>
<P>Congratulations, you have installed, set up an environment for, and tested
Kaffe on Linux.
<H3>More Information </H3>
<P>
<P>For more information on Kaffe, see the Kaffe website at
<A HREF="http://www.kaffe.org">http://www.kaffe.org</A>.
<H2><A NAME="sec: j2se"></A> <A NAME="ss2.4">2.4 Sun J2SE </A>
</H2>
<P>
<H3>Background </H3>
<P>
<P>The Sun Java 2, Standard Edition (J2SE) is Sun's production release of
the Java 2 Platform for the Linux operating system. As of the time of this
writing, J2SE is current with JDK 1.2.2 on the Intel architecture.
<H3>Download </H3>
<P>
<P>J2SE can be obtained from
<A HREF="http://developer.java.sun.com/developer/earlyAccess/j2sdk122">http://developer.java.sun.com/developer/earlyAccess/j2sdk122</A>.
<P>
<P>You will need to register with Sun and agree to the license online before
downloading.
<H3>Installation </H3>
<P>
<P>I suggest installing files in the /usr/local directory. After downloading
the files, run:
<PRE>
mkdir /usr/local/sun
mv jdk1_2_2rc1-linux-i386.tar.gz /usr/local/sun
</PRE>
<P>You can now open the distribution package. To do this, type:
<PRE>
tar zxvf jdk1_2_2rc1-linux-i386.tar.gz
</PRE>
<P>Under the /usr/local/sun directory, you now should see the jdk1.2.2 directory.
<P>
<P>The above example shows JDK 1.2.2 release candidate 1 for the Intel architecture.
Substitute the filenames as appropriate.
<H3>Setting up Your Environment </H3>
<P>
<P>The environment variables to set up are:
<UL>
<LI>JAVA_HOME </LI>
<LI>PATH </LI>
<LI>CLASSPATH </LI>
</UL>
<P>The JAVA_HOME environment variable references the home directory of your
JDK installation. Set your JAVA_HOME environment variable to the directory
into which you just installed a version of J2SE.
<PRE>
export JAVA_HOME=/usr/local/sun/jdk1.2.2
</PRE>
<P>The $JAVA_HOME/bin directory has the Java compiler (javac) and the
Java Virtual Machine (java) as well as other necessary programs for development.
Add $JAVA_HOME/bin to your PATH.
<PRE>
export PATH=$JAVA_HOME/bin:$PATH
</PRE>
<P>Note that $JAVA_HOME/bin was added to the front of the PATH so that
the installed JDK will be used rather than any JDK that might have come with
your Linux distribution.
<P>To confirm that your PATH is correctly set up, check which Java compiler
and JVM will be used.
<PRE>
which javac
which java
</PRE>
<P>The output should reference javac and java in your $JAVA_HOME/bin
directory.
<P>The CLASSPATH environment variable references all JARs and directories
that you will need to compile and run Java programs.
<P>For JDK 1.2.2, you don't need to initially add any JARs to your CLASSPATH.
JARs can be packaged in either .jar or .zip files.
<PRE>
export CLASSPATH=$CLASSPATH:.
</PRE>
<H3>Confirming Your Installation </H3>
<P>
<P>You are now ready to compile and run a simple application. Create the
following program.
<PRE>
class HelloWorld {
public static void main (String[] args) {
System.out.println(&quot;Hello, World!&quot;);
}
}
</PRE>
<P>Compile the program with the Java compiler.
<PRE>
javac HelloWorld.java
</PRE>
<P>If the compiler produces errors, double check the syntax and confirm your
PATH and CLASSPATH.
<P>Run the program with the JVM.
<PRE>
java HelloWorld
</PRE>
<P>If the JVM produces errors, confirm your PATH and CLASSPATH.
<P>You should see the following output:
<PRE>
Hello, World!
</PRE>
<P>Congratulations, you have installed, set up an environment for, and tested
the Sun J2SE for Linux.
<H3>More Information </H3>
<P>
<P>For more information on Sun J2SE, see the Sun Java website at
<A HREF="http://java.sun.com">http://java.sun.com</A>. There are excellent
discussion forums available where you might be able to find answers to various
questions.
<HR>
<A HREF="Enterprise-Java-for-Linux-HOWTO-3.html">Next</A>
<A HREF="Enterprise-Java-for-Linux-HOWTO-1.html">Previous</A>
<A HREF="Enterprise-Java-for-Linux-HOWTO.html#toc2">Contents</A>
</BODY>
</HTML>