SunJava5OnFedora

Sun Java 5 on Fedora

This guide is derived from my original JpackageJava article that was written around the time of Fedora Core 4. Since then, much has changed: the X Window System used on Fedora has changed to Modular X, which means that many programs and their data have moved around in the filesystem, some of Sun's Java platform has been released as free software (OpenJDK) in the form of Iced Tea on Fedora, and even the package management tools have gained some useful options that make this process simpler than it once was.

Sun Java 5 is now "old" software, with Sun Java 6 being the current generation. However, there is still plenty of software out there that requires Java 5 and won't actually run with later versions. This guide is for the people that need to use such software on Fedora. I've tested it on Fedora 8 and 9 but believe it should work on Fedora 7 too.

Users of Red Hat Enterprise Linux 5 can find official Red Hat packages of Sun Java 5 (java-1.5.0-sun) in the RHEL Supplementary channel on Red Hat Network.

JPackage Project

This guide is based on building RPM packages for Sun Java "the JPackage way". This is because:

  1. RPM packages are easier to install, upgrade, and uninstall on Fedora than other packaging techniques
  2. Fedora's own java-related packages are designed to be compatible with JPackage

However, JPackage's Sun Java packages are still targeted at distributions that use the old filesystem layout, and this leads to problems when trying to install and use the native JPackage packages on current Fedora releases. For this reason, I have created a modified version of the JPackage java-1.5.0-sun package that addresses many of these issues, and this guide uses the modified package. For those that are interested, the differences between my package and the JPackage version (which are limited to the spec file) can be found here. The key differences are:

  • Dependencies are fixed for Fedora compatibility
  • The complex mechanism for maintaining Java plugin symlinks for Mozilla and Firefox (which doesn't actually work in Fedora) is replaced by simply using the alternatives system to maintain a single symlink in /usr/lib/mozilla/plugins, which works just fine for all gecko-based browsers as far as I know

  • A link to the Java Web Start program is added in /usr/bin, again maintained using the alternatives system (Fedora 9 uses this approach in OpenJDK too)

  • The /etc/mailcap and /etc/mime.types files, which belong to base Fedora packages, are not edited as part of the RPM install; instead, the desktop MIME database is updated to support applications using Java Web Start, which now works "out of the box" in Firefox and maybe other browsers too

  • The dependency on /usr/sbin/chkfontpath (and all uses of it) are removed; font paths are now set by dropping a symlink in the /etc/X11/fontpath.d directory instead (the chkfontpath package has been removed from the distribution in Fedora 9)

Create RPM Build Environment

If you have not built RPM packages using your regular user account (not root) before, you should create an RPM build environment for your account before going any further.

Download jdk-1_5_0_16-linux-i586.bin from Sun

  1. Go to http://java.sun.com/j2se/1.5.0/download.jsp

  2. Click on the Download link for JDK 5.0 Update 16

  3. Select the Linux platform from the drop-down list, and check the box marked I agree to the Java Development Kit 5.0 License Agreement (for x86_64, select Linux x64 as the platform)

  4. Click on the Continue button

  5. Click the link jdk-1_5_0_16-linux-i586.bin (jdk-1_5_0_16-linux-amd64.bin for x86_64) to download the file

/!\ The x86_64 version does not include Java Web Start or the browser plugin, for which you should build and use the i586 version.

Copy jdk-1_5_0_16-linux-i586.bin to SOURCES

{i} You might have a different download directory for your browser.

[localhost ~]$ cd download/
[localhost download]$ ls
jdk-1_5_0_16-linux-i586.bin
[localhost download]$ cp jdk-1_5_0_16-linux-i586.bin ~/rpmbuild/SOURCES/
[localhost download]$

/!\ For installs on x86_64 systems, the filename is of course jdk-1_5_0_16-linux-amd64.bin

Download java-1.5.0-sun-1.5.0.16-1.0.cf.nosrc.rpm

[localhost ~]$ cd download
[localhost download]$ wget http://mirror.city-fan.org/ftp/contrib/java/java-1.5.0-sun-1.5.0.16-1.0.cf.nosrc.rpm
--17:09:23--  http://mirror.city-fan.org/ftp/contrib/java/java-1.5.0-sun-1.5.0.16-1.0.cf.nosrc.rpm
           => `java-1.5.0-sun-1.5.0.16-1.0.cf.nosrc.rpm'
Resolving mirror.city-fan.org... 216.250.164.123, 212.56.100.58
Connecting to mirror.city-fan.org|216.250.164.123|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18,475 (18K) [application/x-rpm]

100%[=======================================================================>] 18,475        86.16K/s             

17:09:23 (85.95 KB/s) - `java-1.5.0-sun-1.5.0.16-1.0.cf.nosrc.rpm' saved [18475/18475]

[localhost download]$

Build Java RPM Packages

[localhost download]$ rpmbuild --rebuild java-1.5.0-sun-1.5.0.16-1.0.cf.nosrc.rpm
Installing java-1.5.0-sun-1.5.0.16-1.0.cf.nosrc.rpm
warning: InstallSourcePackage: Header V3 DSA signature: NOKEY, key ID b56a8bac
warning: user paul does not exist - using root
warning: group paul does not exist - using root
warning: user paul does not exist - using root
warning: group paul does not exist - using root
warning: user paul does not exist - using root
warning: group paul does not exist - using root
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.28098
+ umask 022
+ cd /nis-home/phowarth/BUILD/BUILD
+ rm -rf /home/paul/rpmbuild/BUILD/jdk1.5.0_16
+ export MORE=10000
+ MORE=10000
+ sh /home/paul/rpmbuild/SOURCES/jdk-1_5_0_16-linux-i586.bin
...
omitted
...
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.5.0-sun-1.5.0.16-1.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.5.0-sun-devel-1.5.0.16-1.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.5.0-sun-src-1.5.0.16-1.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.5.0-sun-demo-1.5.0.16-1.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.5.0-sun-plugin-1.5.0.16-1.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.5.0-sun-fonts-1.5.0.16-1.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.5.0-sun-alsa-1.5.0.16-1.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.5.0-sun-jdbc-1.5.0.16-1.0.cf.i586.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.23655
+ umask 022
+ cd /home/paul/BUILD/BUILD
+ cd jdk1.5.0_15
+ rm -rf /var/tmp/java-1.5.0-sun-1.5.0.16-1.0.cf-buildroot
+ exit 0
Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.67658
+ umask 022
+ cd /home/paul/rpmbuild/BUILD
+ rm -rf jdk1.5.0_16
+ exit 0
[localhost download]$

{i} To build the 32-bit versions of the package on a 64-bit machine, use:

[localhost download]$ setarch i386 rpmbuild --rebuild java-1.5.0-sun-1.5.0.16-1.0.cf.nosrc.rpm

Remove Any Old Cruft

If you have followed earlier versions of this or other guides that involved manually configuring the browser plugin in the /usr/lib/mozilla/plugins directory or Java Web Start as /usr/bin/javaws, remove these hacks:

$ sudo rm -f /usr/lib/mozilla/plugins/libjavaplugin_oji.so /usr/bin/javaws

Neither of these are available for the x86_64 architecture so this step is not necessary there.

Install Java Runtime Environment

It is not necessary to install all of the RPMs you have just built if you only need to run java applications and use the web plugin. For these applications, you only need the base package and the fonts, alsa, and plugin subpackages:

[localhost ~]$ cd ~/rpmbuild/RPMS/i586/
[localhost i586]$ ls -1
java-1.5.0-sun-1.5.0.16-1.0.cf.i586.rpm
java-1.5.0-sun-alsa-1.5.0.16-1.0.cf.i586.rpm
java-1.5.0-sun-demo-1.5.0.16-1.0.cf.i586.rpm
java-1.5.0-sun-devel-1.5.0.16-1.0.cf.i586.rpm
java-1.5.0-sun-fonts-1.5.0.16-1.0.cf.i586.rpm
java-1.5.0-sun-jdbc-1.5.0.16-1.0.cf.i586.rpm
java-1.5.0-sun-plugin-1.5.0.16-1.0.cf.i586.rpm
java-1.5.0-sun-src-1.5.0.16-1.0.cf.i586.rpm
[localhost i586]$ sudo yum --nogpgcheck localinstall java-1.5.0-sun{,-alsa,-fonts,-plugin}-1.5.0*.rpm
Loading "installonlyn" plugin
Setting up Local Package Process
Examining java-1.5.0-sun-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun - 1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-alsa-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun - alsa-1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-fonts-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun-fonts - 1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-plugin-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun-plugin - 1.5.0.16-1.0.cf.i586
Marking java-1.5.0-sun-1.5.0.16-1.0.cf.i586.rpm to be installed
Marking java-1.5.0-sun-alsa-1.5.0.16-1.0.cf.i586.rpm to be installed
Marking java-1.5.0-sun-fonts-1.5.0.16-1.0.cf.i586.rpm to be installed
Marking java-1.5.0-sun-plugin-1.5.0.16-1.0.cf.i586.rpm to be installed
--> Running transaction check
---> Package java-1.5.0-sun-fonts.i586 0:1.5.0.16-1.0.cf set to be updated
---> Package java-1.5.0-sun.i586 0:1.5.0.16-1.0.cf set to be updated
--> Processing Dependency: libXp.so.6 for package: java-1.5.0-sun
---> Package java-1.5.0-sun-alsa.i586 0:1.5.0.16-1.0.cf set to be updated
---> Package java-1.5.0-sun-plugin.i586 0:1.5.0.16-1.0.cf set to be updated
--> Running transaction check
---> Package libXp.i386 0:1.0.0-8.fc8 set to be updated
--> Finished Dependency Resolution

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 java-1.5.0-sun-alsa     i586       1.5.0.16-1.0.cf  java-1.5.0-sun-alsa-1.5.0.16-1.0.cf.i586.rpm   66 k
 java-1.5.0-sun-fonts    i586       1.5.0.16-1.0.cf  java-1.5.0-sun-fonts-1.5.0.16-1.0.cf.i586.rpm  2.0 M
 java-1.5.0-sun-plugin   i586       1.5.0.16-1.0.cf  java-1.5.0-sun-plugin-1.5.0.16-1.0.cf.i586.rpm  1.7 M
Installing for dependencies:
 java-1.5.0-sun          i586       1.5.0.16-1.0.cf  java-1.5.0-sun-1.5.0.16-1.0.cf.i586.rpm   85 M
 libXp                   i386       1.0.0-8.fc8      fedora             22 k

Transaction Summary
=============================================================================
Install      6 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 88 M
Is this ok [y/N]: y

Downloading Packages:
(1/1): libXp-1.0.0-8.fc8. 100% |=========================|  22 kB    00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: libXp                        ######################### [1/5] 
  Installing: java-1.5.0-sun               ######################### [2/5] 
  Installing: java-1.5.0-sun-plugin        ######################### [3/5] 
  Installing: java-1.5.0-sun-fonts         ######################### [4/5] 
  Installing: java-1.5.0-sun-alsa          ######################### [5/5] 

Installed: java-1.5.0-sun-alsa.i586 0:1.5.0.16-1.0.cf java-1.5.0-sun-fonts.i586 0:1.5.0.16-1.0.cf java-1.5.0-sun-plugin.i586 0:1.5.0.16-1.0.cf
Dependency Installed: java-1.5.0-sun.i586 0:1.5.0.16-1.0.cf libXp.i386 0:1.0.0-8.fc8
Finished Transaction
[localhost i586]$

/!\ Note that the java-1.5.0-sun-plugin package is not available for the x86_64 architecture, so use these commands instead on x86_64:

[localhost ~]$ cd ~/rpmbuild/RPMS/x86_64
[localhost x86_64]$ sudo yum --nogpgcheck localinstall java-1.5.0-sun{,-alsa,-fonts}-1.5.0*.rpm

Install Java Development Environment

If you also want to build or develop Java applications yourself, install all of the RPM packages to get the full development environment. Skip this step if you only need the runtime environment from the previous step.

[localhost i586]$ sudo yum --nogpgcheck localinstall java-1.5.0-sun*.rpm
Setting up Local Package Process
Examining java-1.5.0-sun-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun - 1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-alsa-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun-alsa - 1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-demo-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun-demo - 1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-devel-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun-devel - 1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-fonts-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun-fonts - 1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-jdbc-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun-jdbc - 1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-plugin-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun-plugin - 1.5.0.16-1.0.cf.i586
Examining java-1.5.0-sun-src-1.5.0.16-1.0.cf.i586.rpm: java-1.5.0-sun-src - 1.5.0.16-1.0.cf.i586
Marking java-1.5.0-sun-demo-1.5.0.16-1.0.cf.i586.rpm to be installed
Marking java-1.5.0-sun-devel-1.5.0.16-1.0.cf.i586.rpm to be installed
Marking java-1.5.0-sun-jdbc-1.5.0.16-1.0.cf.i586.rpm to be installed
Marking java-1.5.0-sun-src-1.5.0.16-1.0.cf.i586.rpm to be installed
java-1.5.0-sun-1.5.0.16-1.0.cf.i586.rpm: does not update installed package.
java-1.5.0-sun-alsa-1.5.0.16-1.0.cf.i586.rpm: does not update installed package.
java-1.5.0-sun-fonts-1.5.0.16-1.0.cf.i586.rpm: does not update installed package.
java-1.5.0-sun-plugin-1.5.0.16-1.0.cf.i586.rpm: does not update installed package.
--> Running transaction check
---> Package java-1.5.0-sun-jdbc.i586 0:1.5.0.16-1.0.cf set to be updated
--> Processing Dependency: /usr/lib/libodbc.so for package: java-1.5.0-sun-jdbc
Importing additional filelist information
--> Processing Dependency: /usr/lib/libodbcinst.so for package: java-1.5.0-sun-jdbc
---> Package java-1.5.0-sun-src.i586 0:1.5.0.16-1.0.cf set to be updated
---> Package java-1.5.0-sun-devel.i586 0:1.5.0.16-1.0.cf set to be updated
---> Package java-1.5.0-sun-demo.i586 0:1.5.0.16-1.0.cf set to be updated
--> Running transaction check
---> Package unixODBC.i386 0:2.2.12-5.fc8 set to be updated
---> Package unixODBC-devel.i386 0:2.2.12-5.fc8 set to be updated
--> Finished Dependency Resolution

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 java-1.5.0-sun-demo     i586       1.5.0.16-1.0.cf  java-1.5.0-sun-demo-1.5.0.16-1.0.cf.i586.rpm   14 M
 java-1.5.0-sun-devel    i586       1.5.0.16-1.0.cf  java-1.5.0-sun-devel-1.5.0.16-1.0.cf.i586.rpm   11 M
 java-1.5.0-sun-jdbc     i586       1.5.0.16-1.0.cf  java-1.5.0-sun-jdbc-1.5.0.16-1.0.cf.i586.rpm   58 k
 java-1.5.0-sun-src      i586       1.5.0.16-1.0.cf  java-1.5.0-sun-src-1.5.0.16-1.0.cf.i586.rpm   17 M
Installing for dependencies:
 unixODBC                i386       2.2.12-5.fc8     local-updates     954 k
 unixODBC-devel          i386       2.2.12-5.fc8     updates           920 k

Transaction Summary
=============================================================================
Install      6 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 44 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): unixODBC-devel-2.2 100% |=========================| 920 kB    00:01     
(2/2): unixODBC-2.2.12-5. 100% |=========================| 954 kB    00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: unixODBC                     ######################### [1/6] 
  Installing: unixODBC-devel               ######################### [2/6] 
  Installing: java-1.5.0-sun-devel         ######################### [3/6] 
  Installing: java-1.5.0-sun-jdbc          ######################### [4/6] 
  Installing: java-1.5.0-sun-src           ######################### [5/6] 
  Installing: java-1.5.0-sun-demo          ######################### [6/6] 

Installed: java-1.5.0-sun-demo.i586 0:1.5.0.16-1.0.cf java-1.5.0-sun-devel.i586 0:1.5.0.16-1.0.cf java-1.5.0-sun-jdbc.i586 0:1.5.0.16-1.0.cf java-1.5.0-sun-src.i586 0:1.5.0.16-1.0.cf
Dependency Installed: unixODBC.i386 0:2.2.12-5.fc8 unixODBC-devel.i386 0:2.2.12-5.fc8
Finished Transaction
[localhost i586]$

Check Java Version

[localhost i586]$ java -version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
Java HotSpot(TM) Server VM (build 1.5.0_16-b02, mixed mode)
[localhost i586]$

{i} On Fedora 8 and later releases, the default java implementation will still be IcedTea at this point; see Switching Between Java Implementations below for how to change this if you want to do so.

Switching Between Java Implementations

The JPackage java RPMs support switching between java implementations using the alternatives system.

[localhost ~]$ sudo /usr/sbin/alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-icedtea/bin/java
   2           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
   3           /usr/lib/jvm/jre-1.5.0-sun/bin/java

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

[localhost ~]$ java -version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
Java HotSpot(TM) Server VM (build 1.5.0_16-b02, mixed mode)
[localhost ~]$ sudo /usr/sbin/alternatives --auto java
[localhost ~]$ java -version
java version "1.7.0"
IcedTea Runtime Environment (build 1.7.0-b21)
IcedTea Client VM (build 1.7.0-b21, mixed mode)

References


CategoryTip

Recent