How To Install SUN Java JDK On Linux


Java Applets are useful on a web page or web site to do things which may not be possible using HTML or Javascript (but keep in mind that not all computers include a Java environment). To build Java applets, you need a Java Compiler (javac), and to compress the applet(s) into a nice neat package, you also need a Java Archiver (jar).

This web page shows you how to install SUN's JDK (Java Development Kit) so that you can use it even if your favorite Linux Distro already comes with an existing Java compiler.

If your Linux Distro already includes a Java compiler and you have no interest in installing or using the SUN compiler, then you can skip this web page.

The following 3 example pages show you how you can make Java Applets on the command line or by using scripts.


DOWNLOAD THE SUN JDK (JAVA DEVELOPMENT KIT)

To begin, you need to get the JDK package and download it to your Desktop. Just go to the Java JDK website and select the JDK (this How-To will install jdk-6u7-linux-i586.bin).

NOTE: You will notice on the download web page that there is an RPM and a non-RPM version for Linux. Even if your Linux Distro is capable of using RPM based packages, this How-To uses the non-RPM version to have more control over the placement location so that it does not conflict with your existing setup (if you have one already).


INSTALL THE JDK

The following steps assume you downloaded the JDK to your "~/Desktop" and that you want to place the JDK (Java Development Kit) in your "~" (home directory). If you want to place it elsewhere, please modify the appropriate steps to fit your choice.
1.
2.

3.
























 
[you@genesis ~]$ cd ~
[you@genesis ~]$ ls -l ~/Desktop/jdk*
-rw-r--r-- 1 you you 78482905 2008-08-08 12:00 jdk-6u7-linux-i586.bin
[you@genesis ~]$ sh ~/Desktop/jdk-6u7-linux-i586.bin
Sun Microsystems, Inc. Binary Code License Agreement

for the JAVA SE DEVELOPMENT KIT (JDK), VERSION 6

SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THE
SOFTWARE IDENTIFIED BELOW TO YOU ONLY UPON THE CONDITION
THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS BINARY
CODE LICENSE AGREEMENT AND SUPPLEMENTAL LICENSE TERMS
(COLLECTIVELY "AGREEMENT"). PLEASE READ THE AGREEMENT
CAREFULLY. BY DOWNLOADING OR INSTALLING THIS SOFTWARE, YOU
ACCEPT THE TERMS OF THE AGREEMENT. INDICATE ACCEPTANCE BY
SELECTING THE "ACCEPT" BUTTON AT THE BOTTOM OF THE
AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY ALL THE
TERMS, SELECT THE "DECLINE" BUTTON AT THE BOTTOM OF THE
AGREEMENT AND THE DOWNLOAD OR INSTALL PROCESS WILL NOT
CONTINUE.

1. DEFINITIONS. "Software" means the identified above in
binary form, any other machine readable materials
(including, but not limited to, libraries, source files,
header files, and data files), any updates or error
corrections provided by Sun, and any user manuals,
programming guides and other documentation provided to you
--More--

  1. cd ~ - Change to the directory where you will hold your JDK. This How-To uses "~" (your home directory).

  2. ls -l ~/Desktop/jdk* - This is optional. Check the location and name of the JDK you downloaded.

  3. sh ~/Desktop/jdk-6u7-linux-i586.bin - The SUN JDK (Java Development Kit) is wrapped within an EULA (End User License Agreement) before you can expand it. Run the script to see, read, and agree with the EULA before you can expand the JDK into your "~" directory. You need to press the SPACE BAR or ENTER keys to read through the EULA, then answer yes or no before it continues.


CLEANUP

When you reach the end of the EULA (End User License Agreement), the JDK is expanded into "~" and you can then cleanup by removing the downloaded file.
1.










2.
3.
 
[you@genesis ~]$ ls -l
drwxr-xr-x 2  you you   97 2008-08-08 12:00 Desktop/
drwxr-xr-x 2  you you    6 2008-08-08 12:00 Documents/
drwxr-xr-x 2  you you    6 2008-08-08 12:00 Download/
drwxr-xr-x 10 you you 4096 2008-08-08 12:00 jdk1.6.0_07/
drwxr-xr-x 2  you you    6 2008-08-08 12:00 Music/
drwxr-xr-x 2  you you    6 2008-08-08 12:00 Pictures/
drwxr-xr-x 2  you you    6 2008-08-08 12:00 temp/
drwx------ 5  you you   54 2008-08-08 12:00 tmp/
drwxr-xr-x 2  you you    6 2008-08-08 12:00 Pictures/
drwxr-xr-x 2  you you    6 2008-08-08 12:00 Videos/
[you@genesis ~]$ rm -f ~/Desktop/jdk-6u7-linux-i586.bin              
[you@genesis ~]$ exit

  1. ls -l - Optional step. Display the new JDK Compiler directory.

  2. rm -f ~/Desktop/jdk-6u7-linux-i586.bin - Cleanup. Remove the JDK you downloaded earlier.

  3. exit - You are done installing the JDK.


MAKE SCRIPTS TO COMPILE YOUR JAVA

As you can see above, not many steps were used to install the SUN JDK. This allows you to use the SUN JDK even if your Linux install already comes with a Java Compiler.

If your Linux Distro already has an existing Java Compiler and you want to build Java applets using the compiler that came with your Linux Distribution, then follow the steps shown on the following example pages.

If you want to build Java applets using the SUN JDK, then you need to also insert 3 additional "export" lines and use scripts only because you need the exported information. The example shown below shows you the clock script with the additional "export" information required to compile Java programs. Please modify the "export" info to match your choice of JDK toolkit location and the version you downloaded.

#!/bin/sh
export JAVA_HOME=/home/you/jdk1.6.0_07
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$CLASSPATH:.

cd ~/temp

# Create compiled code from java file.
javac -deprecation clock.java

# Create compressed jar archive from compiled file.
jar cvf clock.jar clock.class

# Cleanup results; clock.class not needed.
rm -f clock.class

# Show results
ls -l clock.*


Other Java Pages On This Web Site
Example Clock Example Spreadsheet Example Rubik's Cube A Few Games

Other Pages On This Web Site
Home Page Backup With Tar Disk Image Backup BOINC On Linux Ship Arcade PicDis Disassembler


Powered by WebRing.

Copyright© 2000..2010 Joe's Cat

counter