Tuesday, April 10, 2007

Installing jdk1.3.1 in Fedora6 or other Linux versions

Installing jdk1.3.1 in Fedora6 or other Linux versions
This is probably the hactic task to install jdk1.3.1 in Latest flavours of Linux. Installing the rpm is damn easy but to get it work is not so easy.
Well, let me start from downloading the jdk1.3.1 package from sun site.
Go to url http://java.sun.com and in the search bar just type "jdk1.3.1" and press enter. It will show you many results. To move to the downloads section, see carefully that the result which is shown belongs to a particular category. On that result page there is "Downloads" link. Click on that now Downloads section will be searched for "jdk1.3.1". And probably you will get many versions of "jdk1.3.1_*". Here * shows the different versions. Just choose one of them and it will move you to the downloads section. Download by clicking on the hyper link after accepting the agreement. Save the file in the users home directory.
Now, go to the terminal(bash shell), and move to that directory where the file is saved. then type
rpm -ivh jdk1.3.1_*
It will show you the progress bar and extract the files to /usr/java/jdk1.3.1_*
Move to that directory in the bin folder. and try to run ./java or ./javac
If it is running then probably everything is fine and you can start working on that, but in the latest flavours of Linux have the new versions of libstdc++ which are not supported by jdk1.3.1_*. So, you may probably get the error something like this :-
ot finding libstdc++-libc6.1-1.so.2.

So, for that you need to create a soft link for the file
libstdc++-libc6.1-1.so.2 ->(which will point to) libstdc++-2-libc6.1-1-2.9.0.so

ln -s libstdc++-2-libc6.1-1-2.9.0.so libstdc++-libc6.1-1.so.2


Well, do have that library you need to install "compat-libstdc++-296-2.96-132.fc4.rpm". If you don't know which version you are running run the command
rpm -qa | grep std
It will show you a list which are already installed in your system. After installing that, the above error will get removed now it will give a new error GLIBC_2.0. Its given below:
Error occurred during initialization of VM
Unable to load native library: /usr/java/jdk1.3.1/jre/lib/i386/libjava.so: symbol __libc_wait, version GLIBC_2.0 not defined in file libc.so.6 with link time reference

Now, to remove that error
create a file named libcwait.c
#include
#include
#include
#include
pid_t
__libc_wait (int *status)
{
int res;
asm volatile ("pushl %%ebx\n\t"
"movl %2, %%ebx\n\t"
"movl %1, %%eax\n\t"
"int $0x80\n\t"
"popl %%ebx"
: "=a" (res)
: "i" (__NR_wait4), "0" (WAIT_ANY), "c" (status), "d" (0),
"S" (0));
return res;
}

Compile it using
gcc -shared -o libcwait.so libcwait.c -fpic -O

Now export it
export LD_PRELOAD=/usr/java/jdk1.3.1/jre/lib/i386/libcwait.so

Now create one more file named hswaitpid.c
#include
#include

pid_t hslibc_waitpid(pid_t pid, int *status, int options) {
return waitpid(pid, status, options);
}

compile it using
gcc -shared -O3 -o libhswaitpid.so hswaitpid.c
Now do the following
cd /usr/java/jdk1.3.1/jre/lib/i386/; perl -e "while(<>) {" -e "s/__libc_wait/libc_wait/;" -e "print;" -e"}" libjava.so > libjava.so.tmp
mv libjava.so libjava.so.orig
mv libjava.so.tmp libjava.so
echo $LD_PRELOAD
mv libjava.so.orig libjava.so

Thats it, now you just a global variable using
export


Here, I am giving the steps to follow, by just copying history and removing the unnecessary steps.
732 rpm -ivh ~/test/java/jdk-1.3.1.i386.rpm
733 ls
734 type java
735 java
736 ls jdk1.3.1/bin/javac
737 jdk1.3.1/bin/javac
738 cd jdk1.3.1/jre/lib/i386/
740 vi libcwait.c
741 gcc -02 -shared -o libcwait.so -fpic libwait.c
742 gcc -02 -shared -o libcwait.so -fpic libcwait.c
743 gcc -shared -o libcwait.so libcwait.c -fpic -O
744 gcc -shared -o libcwait.so libcwait.c -fpic -O
745 gcc -shared -o libcwait.so libcwait.c -fpic -O
746 vi libcwait.c
747 gcc -shared -o libcwait.so libcwait.c -fpic -O
750 java
751 export LD_PRELOAD=/usr/java/jdk1.3.1/jre/lib/i386/libcwait.so 4
754 echo $LD_LIBRARY_PATH
755 echo $LD_PRELOAD
756 export LD_LIBRARY_PATH=''
757 java
758 javac
759 ls
760 vi javac (class javatest {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
)/* got to know that java program can't be javac

761 mv javatest
762 mv javac javatest.java
763 javac javatest.java
764 ls
765 java javatest
766 vi /etc/bashrc
767 vi ~/.bash_profile
768 system-config-network
769 ll
770 ll
771 cd test/
772 ls
773 cd java/
774 ll
775 rpm -qa | grep jdk
776 /usr/java/jdk1.3.1/bin/javac
777 ls
778 cd ..
779 ls
780 cd ..
781 ls
783 java
784 cd libcheck/
785 ls
786 vi libcwait.c
787 ll
788 vi compile.txt
789 mkdir test
790 cd test
791 vi hswaitpid.c
792 gcc -shared -O3 -o libhswaitpid.so hswaitpid.c
793 ll
794 ll
795 pwd
796 cd /usr/java/jdk1.3.1/
797 ls
798 cd bin
799 ls
800 ./javac
801 ./java
802 echo $LD_LIBRARY_PATH
803 echo $LD_PRELOAD
804 export
805 set
806 javac
807 java
808 java
809 . ~/.bash_profile
810 java
811 java
812 cd /usr/java/jdk1.3.1/jre/lib/i386/; perl -e "while(<>) {" -e "s/__libc_wait/libc_wait/;" -e "print;" -e"}" libjava.so > libjava.so.tmp
813 mv libjava.so libjava.so.orig
814 mv libjava.so.tmp libjava.so
815 echo $LD_PRELOAD
816 mv libjava.so.orig libjava.so

last step type in .bash_profile
export LD_PRELOAD=/usr/java/jdk1.3.1/jre/lib/i386/libcwait.so

Even though it is a bit confusing. I will try to make it more concise but till then you can work around this only. (am I a good writer ... naah) but it will be interesting for those working around and getting some internals.
My sincere thannks to Rajiv Ranjan Sir.
Good Luck

No comments :

Post a Comment