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 OpenJDK as shipped in Fedora 16 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 17 but believe it should work on older releases down to Fedora 7 and even CentOS 5 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.

For a guide to installing Java SE 7 on Fedora/RHEL, see OracleJava7OnFedora.

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.

Since forking from the JPackage version, this package has diverged quite significantly and is now much closer to the packages that Red Hat makes available for its Red Hat Enterprise Linux 5 customers:

  • 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(64)/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 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 alsa and fonts packages have been merged into the main package

  • The 64-bit versions can be parallel-installed with the 32-bit versions
  • Lots of legacy font compatibility scripting has been dropped

For those that are interested, the differences between my package and the JPackage version can be found here.

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-6u45-linux-i586.bin from Oracle

  1. Go to http://www.oracle.com/technetwork/java/javase/downloads/index.html

  2. Click on the Download JDK button for Java SE 6 Update 45

  3. You need to accept the Oracle Binary Code License Agreement for Java SE before continuing

  4. Download the Linux x86 - Self Extracting Installer (jdk-6u45-linux-i586.bin), or on x86_64, the Linux x64 - Self Extracting Installer (jdk-6u45-linux-x64.bin)

Download the Timezone Updater from Oracle

  1. Go to http://www.oracle.com/technetwork/java/javase/downloads/index.html

  2. Click on the Download button for JDK DST Timezone Update Tool - 1.3.53

  3. Check the box agreeing to the Java SE Timezone Updater License Agreement

  4. Download the Java SE Timezone Updater 1.3.53 (tzupdater-1_3_53-2012j.zip)

Copy Downloaded Files to SOURCES

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

[localhost ~]$ cd download/
[localhost download]$ ls
jdk-6u45-linux-i586.bin tzupdater-1_3_53-2012j.zip
[localhost download]$ cp -p jdk-6u45-linux-i586.bin tzupdater-1_3_53-2012j.zip ~/rpmbuild/SOURCES/
[localhost download]$

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

Download java-1.6.0-sun-1.6.0.45-2.0.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.45-2.0.cf.nosrc.rpm
--2014-01-22 10:00:00--  http://mirror.city-fan.org/ftp/contrib/java/java-1.6.0-sun-1.6.0.45-2.0.cf.nosrc.rpm
Resolving mirror.city-fan.org... 212.56.100.58
Connecting to mirror.city-fan.org|212.56.100.58|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 278406 (272K) [application/x-rpm]
Saving to: `java-1.6.0-sun-1.6.0.45-2.0.cf.nosrc.rpm'

100%[========================================================>] 278,406     1.01M/s   in 0.3s

2014-01-22 10:00:00 (1.01 MB/s) - `java-1.6.0-sun-1.6.0.45-2.0.cf.nosrc.rpm' saved [278406/278406]

[localhost download]$

Build Java RPM Packages

[localhost download]$ rpmbuild --rebuild java-1.6.0-sun-1.6.0.45-2.0.cf.nosrc.rpm
Installing java-1.6.0-sun-1.6.0.45-2.0.cf.nosrc.rpm
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.Ym5Ayh
+ umask 022
+ cd /home/paul/rpmbuild/BUILD
+ cd /home/paul/rpmbuild/BUILD
+ rm -rf jdk1.6.0_45
+ /usr/bin/mkdir -p jdk1.6.0_45
+ cd jdk1.6.0_45
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ export MORE=10000
+ MORE=10000
+ cd /home/paul/rpmbuild/BUILD
+ sh /home/paul/rpmbuild/SOURCES/jdk-6u45-linux-i586.bin
+ cd -
/home/paul/rpmbuild/BUILD/jdk1.6.0_45
+ cd /home/paul/rpmbuild/BUILD
+ cd jdk1.6.0_45
+ /usr/bin/unzip /home/paul/rpmbuild/SOURCES/tzupdater-1_3_53-2012j.zip
Archive:  /home/paul/rpmbuild/SOURCES/tzupdater-1_3_53-2012j.zip
   creating: tzupdater-1.3.53-2012j/
  inflating: tzupdater-1.3.53-2012j/README
  inflating: tzupdater-1.3.53-2012j/tzupdater.jar
+ STATUS=0
...
omitted
...
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-1.6.0.45-2.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-devel-1.6.0.45-2.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-src-1.6.0.45-2.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586.rpm
Wrote: /home/paul/rpmbuild/RPMS/i586/java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.IXNd9J
+ umask 022
+ cd /home/paul/rpmbuild/java-1.6.0-sun/trunk
+ cd jdk1.6.0_45
+ rm -rf /home/paul/rpm/BUILDROOT/java-1.6.0-sun-1.6.0.45-2.0.cf.i386
+ 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.45-2.0.cf.nosrc.rpm

You will need the 32-bit version of glibc for this.

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

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 plugin subpackage:

[localhost ~]$ cd ~/rpmbuild/RPMS/i586/
[localhost i586]$ ls -1
java-1.6.0-sun-1.6.0.45-2.0.cf.i586.rpm
java-1.6.0-sun-devel-1.6.0.45-2.0.cf.i586.rpm
java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586.rpm
java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586.rpm
java-1.6.0-sun-src-1.6.0.45-2.0.cf.i586.rpm
[localhost i586]$ sudo yum --nogpgcheck localinstall java-1.6.0-sun{,-plugin}-1.6.0*.rpm
Loaded plugins: langpacks, presto, refresh-packagekit
Examining java-1.6.0-sun-1.6.0.45-2.0.cf.i586.rpm: 1:java-1.6.0-sun-1.6.0.45-2.0.cf.i586
Marking java-1.6.0-sun-1.6.0.45-2.0.cf.i586.rpm to be installed
Examining java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586.rpm: 1:java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586
Marking java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package java-1.6.0-sun.i586 1:1.6.0.45-2.0.cf will be installed
---> Package java-1.6.0-sun-plugin.i586 1:1.6.0.45-2.0.cf will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================
 Package               Arch Version             Repository                                   Size
==================================================================================================
Installing:
 java-1.6.0-sun        i586 1:1.6.0.45-2.0.cf   /java-1.6.0-sun-1.6.0.45-2.0.cf.i586         92 M
 java-1.6.0-sun-plugin i586 1:1.6.0.45-2.0.cf   /java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586 3.9 M

Transaction Summary
==================================================================================================
Install  2 Packages

Total size: 96 M
Installed size: 96 M
Is this ok [y/N]: y
Downloading Packages:
Running Transaction Check
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 1:java-1.6.0-sun-1.6.0.45-2.0.cf.i586                                          1/2
  Installing : 1:java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586                                   2/2
  Verifying  : 1:java-1.6.0-sun-1.6.0.45-2.0.cf.i586                                          1/2
  Verifying  : 1:java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586                                   2/2

Installed:
  java-1.6.0-sun.i586 1:1.6.0.45-2.0.cf        java-1.6.0-sun-plugin.i586 1:1.6.0.45-2.0.cf

Complete!
[localhost i586]$

/!\ For installs on x86_64 systems, use the x86_64 packages in the ~/rpmbuild/RPMS/x86_64/ directory instead

<!> The current version of the browser plugin requires an executable stack and would only work if the allow_execstack SELinux boolean was set (Bug #628031). This would turn off valuable protection against stack overflow vulnerabilities for the entire system though, so only do this if you really need to install the plugin. It's worth noting though that allow_execstack has been on by default in Fedora releases prior to Fedora 14, and is back on in Fedora 15 onwards.

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: langpacks, presto, refresh-packagekit
Examining java-1.6.0-sun-1.6.0.45-2.0.cf.i586.rpm: 1:java-1.6.0-sun-1.6.0.45-2.0.cf.i586
java-1.6.0-sun-1.6.0.45-2.0.cf.i586.rpm: does not update installed package.
Examining java-1.6.0-sun-devel-1.6.0.45-2.0.cf.i586.rpm: 1:java-1.6.0-sun-devel-1.6.0.45-2.0.cf.i586
Marking java-1.6.0-sun-devel-1.6.0.45-2.0.cf.i586.rpm to be installed
Examining java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586.rpm: 1:java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586
Marking java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586.rpm to be installed
Examining java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586.rpm: 1:java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586
java-1.6.0-sun-plugin-1.6.0.45-2.0.cf.i586.rpm: does not update installed package.
Examining java-1.6.0-sun-src-1.6.0.45-2.0.cf.i586.rpm: 1:java-1.6.0-sun-src-1.6.0.45-2.0.cf.i586
Marking java-1.6.0-sun-src-1.6.0.45-2.0.cf.i586.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package java-1.6.0-sun-devel.i586 1:1.6.0.45-2.0.cf will be installed
---> Package java-1.6.0-sun-jdbc.i586 1:1.6.0.45-2.0.cf will be installed
--> Processing Dependency: /usr/lib/libodbc.so for package: 1:java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586
--> Processing Dependency: /usr/lib/libodbcinst.so for package: 1:java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586
---> Package java-1.6.0-sun-src.i586 1:1.6.0.45-2.0.cf will be installed
--> Running transaction check
---> Package unixODBC.i686 0:2.3.1-1.fc17 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================
 Package               Arch  Version            Repository                                   Size
==================================================================================================
Installing:
 java-1.6.0-sun-devel  i586  1:1.6.0.45-2.0.cf  /java-1.6.0-sun-devel-1.6.0.45-2.0.cf.i586   59 M
 java-1.6.0-sun-jdbc   i586  1:1.6.0.45-2.0.cf  /java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586    83 k
 java-1.6.0-sun-src    i586  1:1.6.0.45-2.0.cf  /java-1.6.0-sun-src-1.6.0.45-2.0.cf.i586     18 M
Installing for dependencies:
 unixODBC              i686  2.3.1-1.fc17       rawhide                                     375 k

Transaction Summary
==================================================================================================
Install  3 Packages (+1 Dependent package)

Total size: 77 M
Total download size: 375 k
Installed size: 78 M
Is this ok [y/N]: y
Downloading Packages:
unixODBC-2.3.1-1.fc17.i686.rpm                                             | 375 kB     00:00
Running Transaction Check
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : unixODBC-2.3.1-1.fc17.i686                                                     1/4
  Installing : 1:java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586                                     2/4
  Installing : 1:java-1.6.0-sun-src-1.6.0.45-2.0.cf.i586                                      3/4
  Installing : 1:java-1.6.0-sun-devel-1.6.0.45-2.0.cf.i586                                    4/4
  Verifying  : unixODBC-2.3.1-1.fc17.i686                                                     1/4
  Verifying  : 1:java-1.6.0-sun-jdbc-1.6.0.45-2.0.cf.i586                                     2/4
  Verifying  : 1:java-1.6.0-sun-devel-1.6.0.45-2.0.cf.i586                                    3/4
  Verifying  : 1:java-1.6.0-sun-src-1.6.0.45-2.0.cf.i586                                      4/4

Installed:
  java-1.6.0-sun-devel.i586 1:1.6.0.45-2.0.cf      java-1.6.0-sun-jdbc.i586 1:1.6.0.45-2.0.cf
  java-1.6.0-sun-src.i586 1:1.6.0.45-2.0.cf

Dependency Installed:
  unixODBC.i686 0:2.3.1-1.fc17

Complete!
[localhost i586]$

Check Java Version

[localhost i586]$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)
[localhost i586]$

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 is 3 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk/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_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)
[localhost ~]$ sudo /usr/sbin/alternatives --config java

There is 3 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.7.0-openjdk/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: 1
[localhost ~]$ java -version
java version "1.7.0_17"
OpenJDK Runtime Environment (fedora-2.3.8.6.fc20-i386)
OpenJDK Client VM (build 23.7-b01, mixed mode, sharing)
[localhost ~]$ sudo /usr/sbin/alternatives --auto java
[localhost ~]$ java -version
java version "1.7.0_17"
OpenJDK Runtime Environment (fedora-2.3.8.6.fc20-i386)
OpenJDK Client VM (build 23.7-b01, mixed mode, sharing)

A separate alternatives setting is used for the browser plugin:

[localhost ~]$ sudo /usr/sbin/alternatives --config libjavaplugin.so

There are 2 programs which provide 'libjavaplugin.so'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/IcedTeaPlugin.so
*+ 2           /usr/lib/jvm/jre-1.6.0-sun/lib/i386/libnpjp2.so

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

Or, on x86_64:

[localhost ~]$ sudo /usr/sbin/alternatives --config libjavaplugin.so.x86_64

There are 2 programs which provide 'libjavaplugin.so.x86_64'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib64/IcedTeaPlugin.so
   2           /usr/lib/jvm/jre-1.6.0-sun.x86_64/lib/amd64/libnpjp2.so

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

There are other less-used alternatives settings that can also be tweaked; if you're not a Java developer then it's unlikely you'll need to change any of these:

  • jce_1.6.0_sun_local_policy (or jce_1.6.0_sun_local_policy.x86_64 on x86_64)

  • jre_sun

  • jre_1.6.0

  • javac (if you've installed java-1.6.0-sun-devel)

  • java_sdk_sun (if you've installed java-1.6.0-sun-devel)

  • java_sdk_1.6.0 (if you've installed java-1.6.0-sun-devel)

References


CategoryTip

Recent