Installing Java on to an OpenVZ Centos 5.2 instance

I’m experimenting with Alfresco, running inside an OpenVZ container on which I’ve installed CentOS 5.2. One of the prerequisites for this project is to have a properly functioning Java VM running on the virtualized CentOS host. This post sets out the steps that I went through and includes a patched spec file to deal with an ODBC issue encountered along the way.

Approach

Follow the instructions from the CentOS wiki on how to install Java on CentOS

If you do this, at least on my install, you will get errors complaining that:

libodbc.so is needed by java-<whatever your version is>
libodbcinst.so is needed by java-<whatever your version is>

This error occurs even if you have unixODBC and unixODBC-devel packages installed. As described in this post, you will need to modify the spec file to fix the issue. However, the post does not quite provide enough detail to complete the job. To actually get everything to work, you need the information from over here.

Clear as mud? 🙂

Here are the steps in more detail, along with a modified spec file.

  1. Scrupulously follow the JavaOnCentOS instructions above in
    “3.4. Step 1. Initial setup”. Don’t forget the .rpmmacros part.
  2. Now, download jdk-6u11-linux-i586.bin (as of March, 2009) from Sun. Note – this is not the RPM version. You’re going to build the RPM version. We’re basically following the tips from here. However, our goal is to patch the spec file to fix the ODBC issue, not to update the version of the JVM.
  3. Put the downloaded file into ~/rpmbuild/SOURCES
  4. Get the jpackage spec file rpm: wget http://mirrors.dotsrc.org/jpackage/1.7/generic/SRPMS.non-free/java-1.6.0-sun-1.6.0.11-1jpp.nosrc.rpm
  5. Run rpm -ivh java-1.6.0-sun-1.6.0.11-1jpp.nosrc.rpm
  6. This will install the spec file into ~/rpmbuild/SPECS. Now you need to edit the spec file to fix the ODBC problem.
  7. To fix the ODBC problem, I incorporated the ODBC fix from this site.
  8. Alter line 85 Release tag:
    1. Release: 0bjc . I picked this arbitrarily – you will want something different – the idea, as pointed out in the original post is to clearly differentiate your patch from the jpp official package.
  9. Next, you will need to add in the code to fix the ODBC issue. This involves adding in this (this is a slight change from the linked instructions). Put this line after the use_internal_dependency_checker line:
    1. %define our_find_requires %{_builddir}/find_requires
  10. Then, after line 220 or so, add in:
  11. # Kludge to remove bogus odbc dependencies
    cat <<EOF >%{our_find_requires}
    #!/bin/sh
    echo unixODBC
    exec %{__find_requires} | /bin/egrep -v ‘^(libodbc(inst)?.so)$’
    exit 0
    EOF

    chmod +x %{our_find_requires}
    %define __find_requires %{our_find_requires}

  12. Finally, edit the changelog to show what you did to the original rpms. You can then check the changelog later by doing:

    1. rpm -q –changelog <nameofpackage>

Patch File

I have created a patch file that makes the necessary changes to the spec file here: spec.txt. I caution you that I’m a beginner at this sort of thing, so YMMV, no warranties, guarantees, or anything else, and I’m sorry if I broke your OS.

To run the patch file, copy it to your ~/rpmbuild/SPECS/ folder. Assuming that the name is “spec.txt”, you would then change into that folder and run:

patch -b -i spec.txt.

It should patch the spec file for you. You should then review the changes that it makes to the spec file before running.

Creating new RPM’s

Assuming that you are satisfied with the patched spec file, you can then create the new RPM’s by doing:

rpmbuild -bb ~/rpmbuilds/SPECS/java-1.6.0-sun.spec

There will be some errors in the middle of the process. The various posters seem to say that these are OK. Once the process completes, you should have new RPMs in ~/rpmbuilds/RPMS/i586, which you can then install with:

sudo yum –nogpgcheck localinstall *rpm

The reason that you want to use yum rather than rpm for this is that it will try to resolve any dependency issues for you. Hopefully, everything will install.

In my next post, I’ll talk about bundling all of this up into a new vm “template” for OpenVZ.

Links

Advertisements

One thought on “Installing Java on to an OpenVZ Centos 5.2 instance

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s