Java 2 SDK269
9.4.2Getting and Installing Java SDK from Sun
You can download the current version from http://java.sun.com. The file is available as
j2sdk-1_4_0-linux-i386-rpm.bin
. The best way is to copy this file to a temporary
directory and then install it from there. I have copied this file into the
/download
directory
where the first step is to make it executable using the following command:
chmod a+x j2sdk-1_4_0-linux-i386-rpm.bin
Then you can execute this file just by typing in the following command:
./j2sdk-1_4_0-linux-i386-rpm.bin
It will display the license agreement and you have to type in “yes” to agree to this
license agreement. After that the self-extracting file will extract
j2sdk-1_4_0-fcs-
linux-i386.rpm
file that you can install using the rpm package with the help of the fol-
lowing command:
rpm --install j2sdk-1_4_0-fcs-linux-i386.rpm
If you have any previous version of SDK installed on your system, you should un-install it
first. To list files installed by the rpm package, you can use the following command.
rpm --query -l j2sdk-1.4.0-fcs|more
By default, files are installed under the
/usr/java/j2sdk1.4.0/
directory. The
/
usr/java/j2sdk1.4.0/bin
directory contains all binary files for the SDK.
9.4.3Creating jar Files
The
jar
utility is used to create Java-class archives. It can take multiple class files, com-
press these and put them into a single
.jar
file. The syntax for using the
jar
utility is similar
to the
tar
program widely used on Linux and other UNIX systems. The following command
creates a file
myclasses.jar
from two class file
first.class
and
second.class
.
jar cvf myclasses.jar first.class second.class
You can also add or extract classes from the existing
.jar
files. The following command
adds
third.class
to
myclasses.jar
archive.
jar uf myclasses.jar third.class
The following command will extract
second.class
from the
myclasses.jar
file.
jar x second.class
You can also use wild cards with the
jar
command. If you use directory names, all files
in that directory are added to the
.jar
file.
To list all files in a
.jar
file, use t command line option. The following command lists all
files in
myclasses.jar
file.
jar tf myclasses.jar
Next Page >>
<< Previous Page
Back to the Table of Contents