Java

Sun Java Development Kit on FC5

_침묵_ 2006. 8. 29. 02:57

출처 :http://ccl.net/cca/software/SOURCES/JAVA/JSDK-1.5/index.shtml

 

What is the problem with FC5 and JDK from Sun?

 

Fedora Core 5 Linux distribution comes with the GNU Java. This is a part of the popular GNU C compiler suite that also includes support for other programming languages, like Fortran. The GNU Java now supports most of the features of Sun Java 1.4 and in many cases can be augmented by additional open source packages to be almost functionally equivalent to the latest JDK from Sun. It has also some important advantages (e.g., option to produce native machine code) but it is by necessity behind with the features of the latest Java Development Kit from Sun. More information can be found at theGNU Compiler for the Javapage at:http://gcc.gnu.org/java/. Recently Sun announced that it is legal to redistribute their Java Development Kit, however, it is unlikely that it will be a part of Fedora. The reason for this is that Sun Java Development Kit is not provided with the source code, while the Fedora Core Linux only provides packages that are open source.

 

In most cases you will be fine with the Open Source, GNU Java. Most open source projects that need Java Development Kit do work with the GNU Java. But some do not... Especially those that push latest standards to the limits and require the latest features of the Java SDK from Sun. With the race to new standards for Java, you may need the Sun's Java SDK, but you also do not want to break the code that assumes that GNU Java is available on your machine. You will definitely need the Sun JDK if you use theirlatest and greatestIDEs orEnterprisetype solutions. ButYOU DO NOT WANT TO BRUTALLY DELETE/UNINSTALL the GNU Javaor just put the Sun JDK into/optand change the$JAVA_HOMEand$CLASSPATH. Luckily there is a nice solution viaalternativespackage that comes with Fedora. We are even more lucky that there is aJPackage.orgproject and that Fedora supports it.

 

Make Sun JDK your default

 

Start from becoming arootby logging in asrootor bysudoor simply by:

 

  su -

 

and get the latest JDK from Sunhttp://java.sun.com/downloads. Select the Java 2 Platform, Standard Edition (J2SE). Choose the latest edition (at this writing it was 1_5_0_07, i.e., JDK 5.0 Update 7) and get theLinux RPM in self-extracting file(DO NOT DOWNLOADLinux self-extracting file!). You should get a file likejdk-1_5_0_07-linux-i586-rpm.binthat is about 45 MBytes in size. If it does not have therpm.binat the end, you took the wrong one.
Note:There are many approaches to installing Sun JDK under Linux. Some go through the route of building the RPM with paths and directories suitable for Fedora. What I describe here is a different approach in which the original Sun JDK RPM file is used but it isbrought into compliancewith Fedora via creating symbolic links and the
alternativescommand through the JPackage.org RPM package.

 

While you are downloading this large file, please downloads the keys for theJPackagerepository:

 

  rpm --importhttp://jpackage.org/jpackage.asc

 

and install theJPackagerepository information for theyum:

 

  cd /etc/yum.repos.d

  wgethttp://jpackage.org/jpackage.repo

 

If it did not work, maybe you do not havewget. You can check it with:

 

 rpm -qi wget

 

and if you do not have it, install it with:

 

  yum install wget

 

and try again to get thejpackage.repofile. Thejpackage.repofile comes with thejpackage-generalrepository enabled. However, I personally disabled the automatic retrieval of updates and packages from theJPackage.orgrepository by editing the/etc/yum.repos.d/jpackage.repofile and changing line(s)enabled=1to theenabled=0. I do not want to risk the situation when, due to some dependency, the new Java packages will be installed on my machine without my knowledge during updates that are run automatically at night. Moreover, Fedora Core 5 default Java packages are already in the Fedora repositories (i.e., were officiallyblessedby Fedora team), and it is probably better to try these repositories first than to go directly to the JPackage.org and risk messing up some naming convention and/or dependencies. At the same time, JPackage repository can be always enabled inyumby adding the:
--enablerepo=jpackage-generic --enablerepo=jpackage-generic-nonfree

options on the command line. Note... There are Fedora repositories on JPackage.org but there are no files in them from what I see, and there is no repository for the FC5, so do not enable them. Since you will be dealing with RPMs, make also sure that you have packages to manipulate them:

 

  rpm -qi rpm-build

  rpm -qi fedora-rpmdevtools

 

If you do not have them, install them:

 

  yum install fedora-rpmdevtools

  yum install rpm-build

 

Check if you have packages for GNU Java compiler/libraries installed, since you most likely need to have somesymmetrybetween GNU and Sun JDKs so thealternativesis not confused. But, frankly, I do not know the intrinsics of it, though it cannot hurt and disk space is cheap.

 

  yum list available '*gcj*'

 

will list the available but not installed yet pieces ofgcj(GNU Java compiler) and you can install these packages as:

 

  yum installpackage1package2...

 

Please read themanpage foralternatives:

 

  man alternatives

 

When your Sun JDKLinux RPM self-extracting filefinally arrives you need to execute it, since it is a shell script. It contains the license agreement and the compressed RPM package with Sun JDK. It will ask you if you agree to the long license. Sayyes, then it will uncompress the RPM with JDK, and then it will install it. To run it do:

 

  chmod 755 jdk-1_5_0_07-linux-i586-rpm.bin

  ./jdk-1_5_0_07-linux-i586-rpm.bin

 

Unfortunately, the Sun RPM package puts files in different locations than the ones required by Fedora Core 5. After running the script you will see a new directory/usr/java/jdk1.5.0_07with JDK files. Note that the actual RPM is left in the directory where you ran the Sun'sjdk-1_5_0_07-linux-i586-rpm.binscript, however, you do not need to process the RPM, since script already did it. You may, however, use the RPM package if you want to install the JDK on another machine or if you erased the JDK at some point with a the RPM'srpm -e jdk-1.5.0_07-fcscommand. Now, you are ready to install the SUN JDK compatibility RPM from the JPackage.org

 

  yum --enablerepo=jpackage-generic-nonfree install java-1.5.0-sun-compat

 

This will create a bunch of links in the/etc/alternativesand/usr/lib/jvmdirectories and others to the/usr/java/jdk1.5.0_07directory where the Sun JDK distribution resides. To check which files were affected do:

 

  rpm -q -l java-1.5.0-sun-compat

 

Check if the Sun JDK is really a default by doing:

 

 java -version

 

If you get:

 

java version "1.4.2"

gij (GNU libgcj) version 4.1.1 20060525 (Red Hat 4.1.1-1)

 

Copyright (C) 2006 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

(or similar)then something did not work. If you get:

 

java version "1.5.0_07"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)

Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)

 

then the Sun JDK is your default. You can usealternativesto check (or change) the default JDK by:

 

 alternatives --config java

 

It should show something like:

 

There are 2 programs which provide 'java'.

 

 Selection   Command

-----------------------------------------------

  1          /usr/lib/jvm/jre-1.4.2-gcj/bin/java

*+ 2          /usr/lib/jvm/jre-1.5.0-sun/bin/java

 

Enter to keep the current selection[+], or type selection number:

 

Hit[Enter]key if you want Sun JDK to be a default, or enter1if you want to change back to GNU Java. The JPackage compatibility should also make you a link for Java plug-in for Firefox browser. To make sure it did, do:

 

 cd /usr/lib/mozilla/plugins

 ls -l

 

If you get:

 

lrwxrwxrwx 1 root root   77 Jun 1720:47libjavaplugin_oji.so ->

 /usr/lib/jvm/java-1.5.0-sun-1.5.0.07/jre/plugin/i386/ns7/libjavaplugin_oji.so

 

you should be fine. If you do not have it, make this link yourself (but then worry, since something is not right):

 

 cd /usr/lib/mozilla/plugins

 ln -s /usr/lib/jvm/java-1.5.0-sun-1.5.0.07/jre/plugin/i386/ns7/libjavaplugin_oji.so \

   libjavaplugin_oji.so

 

The Firefox should look for plug-ins in the/usr/lib/mozilla/pluginsdirectory. If your Firefox still does not work with Java, put the link above also in the directory/usr/lib/firefox-1.5.0.4/plugins, or whatever is your particular version of Firefox that you can dig out from the script that runs it:/usr/bin/firefoxor whatever is reported by:

 

 which firefox

 

There are different distros of Firefox, so you may bespecialbut for your own sake, useyumto update Firefox.
Now, there will be times, when you want to get rid of Sun JDK and its entries for
alternatives.DO NOT TOUCH THESE LINKS WITH YOUR BARE HANDS. Useyumto uninstall the JPackage Java compatibility package first and then erase the Sun JDK withrpm:

 

yum erase java-1.5.0-sun-compat

rpm -e jdk-1.5.0_07-fcs

 

Be bold... Do not worry... You can always reinstall it as described above. Of course, you can choose to userpmcommand directly rather thanyumto work with packages. Butyumhas a lot of advantages, since it will maintain the packages and upgrades and makes a lot of checks to see if things will not break. But sometimes they break. A popular situation is when you usedrpmto install some package (or the package was installed with aninstall(older package is kept) rather than anupdate(older package is removed). In this case,yumgets confused with dependencies and complains, and it does not want to install a package. To see if this is a case, list all the installed rpm packages for some package name with a command:

 

  rpm -qa | grep "java"

 

for example. If you see two versions of the same rpm, just erase theolder(i.e., with the lower revision number) one. Use the

 

  rpm -e full_package_name_with_version

 

(but skip the.rpm) and then tryyum updateoryum installagain. I am telling you this, since we will definitely have morejavasandcompatscoming, and themess happens. For example (at this time a hypothetical one), if you got stuck with twocompatpackages when updates to the JDK were processed:

 

  rpm -qa | grep "java-1.5.0-sun-compat"

  java-1.5.0-sun-compat-1.5.0.07-1jpp

  java-1.5.0-sun-compat-1.5.0.08-1jpp

 

remove the older package as:

 

  yum erase java-1.5.0-sun-compat-1.5.0.07-1jpp

 

or, if stillno go:

 

  rpm -e java-1.5.0-sun-compat-1.5.0.07-1jpp

 

and try again.

 

So... Where the heck is myJAVA_HOME? Relax...

 

  JAVA_HOME=/usr/lib/jvm/java

  export JAVA_HOME

 

or if you are C-shellish:

 

  setenv JAVA_HOME /usr/lib/jvm/java

 

Jan K. Labanowski
Computational Chemistry List, Ltd.
http://www.ccl.net

 

If you think that I erred, please let me know and I will be thankful and will correct... I promise... One more thing (a disclaimer...): If you believed in anything what I said, and lost time and money, it is your fault... I am telling you again... I may have made a mistake, and I do not guarantee that anything will work as described...

 

jkl at ccl . net

'Java' 카테고리의 다른 글

Ant 1.7: Using Antlibs  (0) 2006.08.30
Runtime.exec()  (1) 2006.07.08
자바 2 SDK 1.5의「데드락 해결 비법」  (0) 2006.07.07