Monday, November 5, 2007

Project, Part 1: Fedora + Sun Java

Glassfish needs Java JDK 5, or 6. Fedora doesn't come with the Sun JDK, but rather GNU Java. Additionally, unlike my experiences with Ubuntu, Fedora does not have a recent implementation of the JDK available from a repository. So I was confronted with this choice:
  1. Try to force Glassfish to work with GNU Java, the default in Fedora, or
  2. Try to force Fedora to use Sun's Java
I decided on the later after reading that none of the java language features new in Java 1.5 are implemented yet in gcj. At the same time, the blog consensus was that installing Sun's Java on Fedora was not straight forward. First, the different java versions could interfere with each other; and second, if installed incorrectly, Sun's java could be accidentally, and unintentionally, 'upgraded' to gcj when installing a system update.

For the most part, I followed a combination of these blogs: blog1, blog2, blog3, blog4. Alas, none of them worked despite following step by step, but in doing so, I learned a lot about what was going on.

The first problem seemed to be related to a dependency difference between JDK 1.5.0 build 11 or 12 and JDK 1.5.0 build 13, which is what I was using. Although each blog listed certain dependencies, none listed the dependency problem I was having. I still don't know what libXtst is, but without it I was unable to install the JDK. With it, I was able to install just fine.

The second problem had to do with the order of installing RPMs. If I tried to install them all at once with a yum -y --nogpgcheck install /usr/src/redhat/RPMS/i586/java*.rpm, it would fail because of an error in the SPEC file dealing with font package locations (detailed here, in the Current Issues section). However, if I installed only java-1.5.0-sun-1.5.0.13-1jpp.i586.rpm first, and then installed the rest, I ended up with a working version (though the font problem remained).

A third problem was that blog1, referenced above, which involved rebuilding the java RPMs via rpmbuild -ba java-1.x.0-sun.spec resulted in a working JRE, but no JDK.

Here is the final version of what worked for me:
  1. Some prerequisites
    1. yum -y install rpmdevtools jpackage-utils rpm-build libXp unixODBC unixODBC-devel libXtst yum-priorities
    2. rpm -Uvh http://www.fedorafaq.org/yum http://rpm.livna.org/livna-release-7.rpm

  2. Get the JPackage Java RPM with
    wget http://mirrors.dotsrc.org/jpackage/1.7/generic/SRPMS.non-free/java-1.5.0-sun-1.5.0.13-1jpp.nosrc.rpm (lists at http://mirrors.dotsrc.org/jpackage/1.7/generic/SRPMS.non-free/)

  3. Download the right JDK binary from Sun (not the self-extracting RPM) for the java version and build version of the JPackage RPM into /usr/src/redhat/SOURCES/

  4. recreate the java rpm
    1. rpmbuild --rebuild java-1.5.0-sun*src.rpm
    2. should create new rpms in /usr/src/redhat/RPMS/i586/

  5. install new java rpms (need the --nogpg option because locally created rpms are not signed)
    1. yum -y --nogpgcheck install /usr/src/redhat/RPMS/i586/java-1.5.0-sun-1.5.0.13-1jpp.i586.rpm
    2. yum -y --nogpgcheck install /usr/src/redhat/RPMS/i586/java*.rpm

  6. check java version with java -version, and that the JDK is installed with javac --help. If the version is not right, or it didn't work, change the default Java system to Sun's with alternatives --config java, and select the right jvm

  7. Set the JAVA_HOME environment variable

    1. Add to /etc/profile
      JAVA_HOME="/usr/lib/jvm/java"
      export JAVA_HOME

    2. run source /etc/profile to read in profile, and check it worked with echo $JAVA_HOME


That's it, now for Glassfish...

No comments: