Creating a Virtual Java RPM

javaSome RPMs (e.g.’s tomcat7-7.0.39-1.jpp6.noarch.rpm) express their dependency upon Java by requiring a RPM that provides capability java (as opposed to, for example, depending on the existence of a file /usr/bin/java). On CentOS, this capability is normally provided by the java-*-openjdk RPM. Therefore, if you execute # yum install tomcat7 on a clean install of CentOS, yum will install OpenJDK in addition to Tomcat 7.

Some people prefer to run the Oracle JRE/JDK instead of OpenJDK. Oracle provides RPMs named jre-version-linux-x64.rpm and jdk-version-linux-x64.rpm to make installing them easier. Unfortunately, these RPMs do not provide the capability java. This means that if you already have the Oracle JRE installed, and you install a RPM which requires the capability java, the OpenJDK will be unnecessarily installed (and might even become the default!).

I solved this dilemma by creating a ‘virtual’ RPM package which provides the capability java by depending on the Oracle JRE. I named this package virtual-java.

Creating this package is quite easy. First I created a Makefile to make building the RPM easier and deal with rpmbuild’s nonsense regarding _topdir:


.PHONY: all
all: dist/$(RPMNAME)

.PHONY: clean
	rm -rf work
	rm -rf dist

dist/$(RPMNAME): work/RPMS/noarch/$(RPMNAME) dist
	cp work/RPMS/noarch/$(RPMNAME) dist/$(RPMNAME)

work/RPMS/noarch/$(RPMNAME): work/BUILD work/RPMS/noarch work/SPECS/virtual-java.spec
	rpmbuild -bb --define="_topdir ${PWD}/work" work/SPECS/virtual-java.spec

work/SPECS/virtual-java.spec: work/SPECS virtual-java.spec
	cat virtual-java.spec | sed -e s/%VERSION%/$(VERSION)/g | sed -e s/%RELEASE%/$(RELEASE)/g > work/SPECS/virtual-java.spec

	if [ ! -d dist ]; then mkdir -p dist; fi
	touch dist
	if [ ! -d work/BUILD ]; then mkdir -p work/BUILD; fi
	touch work/BUILD
	if [ ! -d work/RPMS/noarch ]; then mkdir -p work/RPMS/noarch; fi
	touch work/RPMS/noarch
	if [ ! -d work/SPECS ]; then mkdir -p work/SPECS; fi
	touch work/SPECS

Note how the Makefile defines VERSION and RELEASE, and provides them to the .spec file. This is done because the Makefile needs to know the name of the generated RPM file, which depends on VERSION and RELEASE.

Here is virtual-java.spec:

Name: virtual-java
Version: %VERSION%
Release: %RELEASE%
Summary: Virtual package which provides java but uses the Sun/Oracle JRE
License: None
BuildArch: noarch
Provides: java
Requires: jre > %VERSION%

Virtual package which provides java but uses the Sun/Oracle JRE








Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s