Saturday, September 06, 2008

Install Java j2re 1.4.2_04 on Ubuntu

Some applications we are currently running forced me to have J2RE (Java Runtime Environment) version 1.4.2._04 installed under Ubuntu.

You can still download old versions of Java from the Sun Microsystems website, you only have to go to the archive section to be able to do so. So I downloaded the file j2re-1_4_2_04-linux-i586.bin to install the runtime environment on my laptop. However then I ended up in having some problems.

I did the following steps:
(1)wget the file from the sun site.
(2)Made sure that it was executable by executing chmod +x ~/Desktop/j2re-1_4_2_04-linux-i586.bin
(3)and started the installation with ./j2re-1_4_2_04-linux-i586.bin

First you will get a long Binary Code License Agreement which you have to 'read' and finally approve, however after that I got the following error:


Do you agree to the above license terms? [yes or no]
yes
Unpacking...
tail: cannot open `+417' for reading: No such file or directory
Checksumming...
1
The download file appears to be corrupted. Please refer
to the Troubleshooting section of the Installation
Instructions on the download page for more information.
Please do not attempt to install this archive file.
jlouwers@NL-jlouwers:~/Desktop$

Which stated an error by executing the tail command. This version of Java is a somewhat older version and has a command in the installer which is no longer valid with newer release of the tail command. The tail command is used in the installation script, which is on the top of the bin file, to do a checksum to make sure that the archive you are installing is valid. This to prevent that you install a archive that has been corrupted during downloading or is tampered with before you downloaded it. Now if you are sure that the packet is valid, and you can be quite sure of that when you download it from the sun download website you can solve this problem by editing the installation script inside the .bin file.

You can edit it by using vi. When you open the file in vi you will find the problematic tail command on line 276 stating “tail +417 $0 > $outname”. After this line you enter a if, else fi statement. To solve the problem edit line 276 and comment out line 277 until line 302. So your installation script should look like the following:

tail -n +417 $0 > $outname
#if [ -x /usr/bin/sum ] ; then
# echo "Checksumming..."
#
# sum=`/usr/bin/sum $outname`
# index=1
# for s in $sum
# do
# case $index in
# 1) sum1=$s;
# index=2;
# ;;
# 2) sum2=$s;
# index=3;
# ;;
# esac
# done
# if expr $sum1 != 13852 || expr $sum2 != 13822 ; then
# echo "The download file appears to be corrupted. Please refer"
# echo "to the Troubleshooting section of the Installation"
# echo "Instructions on the download page for more information."
# echo "Please do not attempt to install this archive file."
# exit 1
# fi
#else
# echo "Can't find /usr/bin/sum to do checksum. Continuing anyway."
#fi

“tail -n +417 $0 > $outname” is a valid statement which can be used with the current releases of the tail command and the checksum part is 'removed' from the installation script. If you now execute the installation all should be fine. This is how you can install the Java Runtime Environment on the latest release of Ubuntu. Even do you have to do some things, installing Java on Debian like systems has improved a lot, you can check an older post from some time ago where you can see that installing Java on Debian for example was quite a bit harder. For a complete guide on how to install it, without the code fix part, can be found on this website. This however will not succeed without the code fix when you have a newer version of tail.

5 comments:

Anonymous said...

u saved my day :) (or night) .. thanks

Anonymous said...

Excellent assistance, likewise saved a huge amount of time. Had to try you instructions twice as forgot to edit the "-n" on the tail command the first time.

Anonymous said...

Great, also saved me a bunch of time.

I had to try twice as I forgot the "-n" change in the tail command first time.

Cheers.

Anonymous said...

I try to download jre from sun archive server (http://java.sun.com/products/archive/index.html), but archive seems to be broken. I've changed archive as you describe. But cannot execute extracted elf file. The error is

file #492: bad zipfile offset (local header sig): 11275893
and so on.

Is archive broken on sun server or I do something wrong?

I use ubintu.

Any suggestions?

Anonymous said...

Thank you so much. It saved my time a lot around 2 hours.