SunJava6OnFedora

Sun Java 6 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.

Whilst the current OpenJDK as shipped in Fedora 9 is aimed at being compatible with Sun Java 6, it's not fully there yet. For example, some applications won't work with the javaws included in OpenJDK. This guide is for the people that need to use such software on Fedora. I've tested it to some extent 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 6 (java-1.6.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.6.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-6u7-linux-i586.bin from Sun

  1. Go to http://java.sun.com/javase/downloads/index.jsp

  2. Click on the Download link for JDK 6 Update 7

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

  4. Click on the Continue button

  5. Click the link jdk-6u7-linux-i586.bin (jdk-6u7-linux-x64.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-6u7-linux-i586.bin to SOURCES

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

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

/!\ For installs on x86_64 systems, the filename is of course jdk-6u7-linux-x64.bin

Download java-1.6.0-sun-1.6.0.7-1.1.cf.nosrc.rpm

[localhost ~]$ cd download
[localhost download]$ wget http://mirror.city-fan.org/ftp/contrib/java/java-1.6.0-sun-1.6.0.7-1.1.cf.nosrc.rpm
--2008-09-17 15:38:08--  http://mirror.city-fan.org/ftp/contrib/java/java-1.6.0-sun-1.6.0.7-1.1.cf.nosrc.rpm
Resolving mirror.city-fan.org... 212.56.100.58, 216.250.164.123
Connecting to mirror.city-fan.org|212.56.100.58|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19917 (19K) [application/x-rpm]
Saving to: `java-1.6.0-sun-1.6.0.7-1.1.cf.nosrc.rpm'

100%[=============================================================================================>] 19,917      63.5K/s   in 0.3s

2008-09-17 15:38:10 (63.5 KB/s) - `java-1.6.0-sun-1.6.0.7-1.1.cf.nosrc.rpm' saved [19917/19917]

[localhost download]$

Build Java RPM Packages

[localhost download]$ rpmbuild --rebuild java-1.6.0-sun-1.6.0.7-1.1.cf.nosrc.rpm
Installing java-1.6.0-sun-1.6.0.7-1.0.cf.nosrc.rpm
warning: InstallSourcePackage: Header V4 DSA signature: NOKEY, key ID 161c06b1
warning: user phowarth does not exist - using root
warning: group phowarth does not exist - using root
warning: user phowarth does not exist - using root
warning: group phowarth does not exist - using root
warning: user phowarth does not exist - using root
warning: group phowarth does not exist - using root
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.83863
+ umask 022
+ cd /home/paul/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ rm -rf /home/paul/rpmbuild/BUILD/jdk1.6.0_07
+ export MORE=10000
+ MORE=10000
+ sh /home/paul/rpmbuild/SOURCES/java-1.6.0-sun/jdk-6u7-linux-i586.bin
...
omitted
...
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-1.6.0.7-1.1.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-devel-1.6.0.7-1.1.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-src-1.6.0.7-1.1.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-demo-1.6.0.7-1.1.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-plugin-1.6.0.7-1.1.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-fonts-1.6.0.7-1.1.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-alsa-1.6.0.7-1.1.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-jdbc-1.6.0.7-1.1.cf.i586.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.81478
+ umask 022
+ cd /home/paul/rpmbuild/BUILD
+ cd jdk1.6.0_07
+ rm -rf /var/tmp/java-1.6.0-sun-1.6.0.7-1.1.cf-buildroot
+ exit 0
Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.81478
+ umask 022
+ cd /home/paul/BUILD/BUILD
+ rm -rf jdk1.6.0_07
+ 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.6.0-sun-1.6.0.7-1.1.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.6.0-sun-1.6.0.7-1.1.cf.i586.rpm
java-1.6.0-sun-alsa-1.6.0.7-1.1.cf.i586.rpm
java-1.6.0-sun-demo-1.6.0.7-1.1.cf.i586.rpm
java-1.6.0-sun-devel-1.6.0.7-1.1.cf.i586.rpm
java-1.6.0-sun-fonts-1.6.0.7-1.1.cf.i586.rpm
java-1.6.0-sun-jdbc-1.6.0.7-1.1.cf.i586.rpm
java-1.6.0-sun-plugin-1.6.0.7-1.1.cf.i586.rpm
java-1.6.0-sun-src-1.6.0.7-1.1.cf.i586.rpm
[localhost i586]$ sudo yum --nogpgcheck localinstall java-1.6.0-sun{,-alsa,-fonts,-plugin}-1.6.0*.rpm
Loaded plugins: refresh-packagekit
Setting up Local Package Process
Examining java-1.6.0-sun-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-1.6.0.7-1.1.cf.i586
Marking java-1.6.0-sun-1.6.0.7-1.1.cf.i586.rpm to be installed
Examining java-1.6.0-sun-alsa-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-alsa-1.6.0.7-1.1.cf.i586
Marking java-1.6.0-sun-alsa-1.6.0.7-1.1.cf.i586.rpm to be installed
Examining java-1.6.0-sun-fonts-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-fonts-1.6.0.7-1.1.cf.i586
Marking java-1.6.0-sun-fonts-1.6.0.7-1.1.cf.i586.rpm to be installed
Examining java-1.6.0-sun-plugin-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-plugin-1.6.0.7-1.1.cf.i586
Marking java-1.6.0-sun-plugin-1.6.0.7-1.1.cf.i586.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package java-1.6.0-sun-plugin.i586 0:1.6.0.7-1.1.cf set to be updated
---> Package java-1.6.0-sun-alsa.i586 0:1.6.0.7-1.1.cf set to be updated
---> Package java-1.6.0-sun-fonts.i586 0:1.6.0.7-1.1.cf set to be updated
---> Package java-1.6.0-sun.i586 0:1.6.0.7-1.1.cf set to be updated
--> Processing Dependency: libXp.so.6 for package: java-1.6.0-sun
--> Running transaction check
---> Package libXp.i386 0:1.0.0-11.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package Arch Version        Repository                                     Size
================================================================================
Installing:
 java-1.6.0-sun
       i586 1.6.0.7-1.1.cf java-1.6.0-sun-1.6.0.7-1.1.cf.i586.rpm          35 M
 java-1.6.0-sun-alsa
       i586 1.6.0.7-1.1.cf java-1.6.0-sun-alsa-1.6.0.7-1.1.cf.i586.rpm     36 k
 java-1.6.0-sun-fonts
       i586 1.6.0.7-1.1.cf java-1.6.0-sun-fonts-1.6.0.7-1.1.cf.i586.rpm   1.2 M
 java-1.6.0-sun-plugin
       i586 1.6.0.7-1.1.cf java-1.6.0-sun-plugin-1.6.0.7-1.1.cf.i586.rpm  673 k
Installing for dependencies:
 libXp i386 1.0.0-11.fc9   fedora                                          23 k

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

Total download size: 37 M
Is this ok [y/N]: y
Downloading Packages:
libXp-1.0.0-11.fc9.i386.rpm                                                                           |  23 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.6.0-sun                                    [2/5]
  Installing     : java-1.6.0-sun-alsa                               [3/5]
  Installing     : java-1.6.0-sun-fonts                              [4/5]
  Installing     : java-1.6.0-sun-plugin                             [5/5]

Installed: java-1.6.0-sun.i586 0:1.6.0.7-1.1.cf java-1.6.0-sun-alsa.i586 0:1.6.0.7-1.1.cf java-1.6.0-sun-fonts.i586 0:1.6.0.7-1.1.cf java-1.6.0-sun-plugin.i586 0:1.6.0.7-1.1.cf
Dependency Installed: libXp.i386 0:1.0.0-11.fc9
Complete!
[localhost i586]$

/!\ Note that the java-1.6.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.6.0-sun{,-alsa,-fonts}-1.6.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.6.0-sun*.rpm
Loaded plugins: refresh-packagekit
Setting up Local Package Process
Examining java-1.6.0-sun-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-1.6.0.7-1.1.cf.i586
java-1.6.0-sun-1.6.0.7-1.1.cf.i586.rpm: does not update installed package.
Examining java-1.6.0-sun-alsa-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-alsa-1.6.0.7-1.1.cf.i586
java-1.6.0-sun-alsa-1.6.0.7-1.1.cf.i586.rpm: does not update installed package.
Examining java-1.6.0-sun-demo-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-demo-1.6.0.7-1.1.cf.i586
Marking java-1.6.0-sun-demo-1.6.0.7-1.1.cf.i586.rpm to be installed
Examining java-1.6.0-sun-devel-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-devel-1.6.0.7-1.1.cf.i586
Marking java-1.6.0-sun-devel-1.6.0.7-1.1.cf.i586.rpm to be installed
Examining java-1.6.0-sun-fonts-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-fonts-1.6.0.7-1.1.cf.i586
java-1.6.0-sun-fonts-1.6.0.7-1.1.cf.i586.rpm: does not update installed package.
Examining java-1.6.0-sun-jdbc-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-jdbc-1.6.0.7-1.1.cf.i586
Marking java-1.6.0-sun-jdbc-1.6.0.7-1.1.cf.i586.rpm to be installed
Examining java-1.6.0-sun-plugin-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-plugin-1.6.0.7-1.1.cf.i586
java-1.6.0-sun-plugin-1.6.0.7-1.1.cf.i586.rpm: does not update installed package.
Examining java-1.6.0-sun-src-1.6.0.7-1.1.cf.i586.rpm: java-1.6.0-sun-src-1.6.0.7-1.1.cf.i586
Marking java-1.6.0-sun-src-1.6.0.7-1.1.cf.i586.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package java-1.6.0-sun-jdbc.i586 0:1.6.0.7-1.1.cf set to be updated
--> Processing Dependency: /usr/lib/libodbc.so for package: java-1.6.0-sun-jdbc
Importing additional filelist information
--> Processing Dependency: /usr/lib/libodbcinst.so for package: java-1.6.0-sun-jdbc
---> Package java-1.6.0-sun-devel.i586 0:1.6.0.7-1.1.cf set to be updated
---> Package java-1.6.0-sun-demo.i586 0:1.6.0.7-1.1.cf set to be updated
---> Package java-1.6.0-sun-src.i586 0:1.6.0.7-1.1.cf set to be updated
--> Running transaction check
---> Package unixODBC.i386 0:2.2.12-7.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package  Arch Version        Repository                                  Size
================================================================================
Installing:
 java-1.6.0-sun-demo
          i586 1.6.0.7-1.1.cf java-1.6.0-sun-demo-1.6.0.7-1.1.cf.i586.rpm  10 M
 java-1.6.0-sun-devel
          i586 1.6.0.7-1.1.cf java-1.6.0-sun-devel-1.6.0.7-1.1.cf.i586.rpm
                                                                           17 M
 java-1.6.0-sun-jdbc
          i586 1.6.0.7-1.1.cf java-1.6.0-sun-jdbc-1.6.0.7-1.1.cf.i586.rpm  27 k
 java-1.6.0-sun-src
          i586 1.6.0.7-1.1.cf java-1.6.0-sun-src-1.6.0.7-1.1.cf.i586.rpm   17 M
Installing for dependencies:
 unixODBC i386 2.2.12-7.fc9   fedora                                      962 k

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

Total download size: 44 M
Is this ok [y/N]: y
Downloading Packages:
unixODBC-2.2.12-7.fc9.i386.rpm                                                                        | 962 kB     00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : java-1.6.0-sun-devel                              [1/5]
  Installing     : java-1.6.0-sun-demo                               [2/5]
  Installing     : java-1.6.0-sun-src                                [3/5]
  Installing     : unixODBC                                          [4/5]
  Installing     : java-1.6.0-sun-jdbc                               [5/5]

Installed: java-1.6.0-sun-demo.i586 0:1.6.0.7-1.1.cf java-1.6.0-sun-devel.i586 0:1.6.0.7-1.1.cf java-1.6.0-sun-jdbc.i586 0:1.6.0.7-1.1.cf java-1.6.0-sun-src.i586 0:1.6.0.7-1.1.cf
Dependency Installed: unixODBC.i386 0:2.2.12-7.fc9
Complete!
[localhost i586]$

Check Java Version

[localhost i586]$ java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Server VM (build 10.0-b23, 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.6.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
   3           /usr/lib/jvm/jre-1.6.0-sun/bin/java

Enter to keep the current selection[+], or type selection number: 3
[localhost ~]$ java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)
[localhost ~]$ sudo /usr/sbin/alternatives --auto java
[localhost ~]$ java -version
java version "1.6.0"
OpenJDK  Runtime Environment (build 1.6.0-b09)
OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)

References


CategoryTip

Recent