Thursday, November 18, 2010

Building RPM Packages for Java from jar files

I would like to use the rpm packages software in order to distribute and install Java applications on Linux systems.  There are many documents outlining in detail how to generate rpm files.  However, most of the documents I came across, require the source code and make files to generate the binary rpms.  With Java, I am not using the  make and configure utilities to generate the final .jar product. 

The following instructions outline the steps necessary to create a binary RPM file, which can be used to install a Java .jar file on a Linux system.  My build system is using Fedora 13.

First step is to install the RPM Development Tools.  As the root user, issue the command:

# yum install rpmdevtools

Create a user account which will be used to generate the rpm's.
# useradd rpmmanager

Login as the rpmmanager, and issue the command to setup the rpm build tree.
# rpmdev-setuptree

This will create a rpmbuild directory in the rpmmanager's users home directory.  Create a tmp directory in the rpmbuild directory.


# mkdir ~rpmmanager/rpmbuild/tmp

Edit the ~rpmmanager/.rpmmacros file with path information.  My .rpmmacros file contains the following info:

%_topdir      %(echo $HOME)/rpmbuild
%_tmppath      %(echo $HOME)/rpmbuild/tmp




"rpmbuild" needs a ".spec" file to build a ".rpm" file. Create such a spec file in your project directory.

vi ~rpmmanager/rpmbuild/SPECS/pxNodeManager.spec


Example of my spec file.
Summary: Psydex Node Manager
%define version 1.0
License: Psydex
Group: Applications/System
Name: pxNodeManager
Prefix: /usr/local/bin
Provides: pxNodeManager.jar
Release: 1
URL: http://www.psydex.com
Version: %{version}
BuildRoot: %{builddir}/%{name}-root
%description
Psydex Node Manager provides status to the Psydex Service Manager via JMS.

%prep
%build
%install
pwd
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/local/bin/psydexNodeManager
cd $RPM_BUILD_ROOT/usr/local/bin/psydexNodeManager
cp ~rpmmanager/builds/pxService/dist/pxNodeManager.jar .
%clean
%files
%defattr(-,root,root)
/usr/local/bin/psydexNodeManager/pxNodeManager.jar


The above spec file copies the pxNodeManager.jar file from the location I use to build the .jar.  ("cp ~rpmmanager/builds/pxService/dist/pxNodeManager.jar . ").  One can easily add additional files to the binary rpm, by adding them under the %files section of the spec file.


To create the binary rpm, run the rpmbuild command.
rpmbuild -bb ~rpmmanager/rpmbuild/SPECS/pxNodeManager.spec

The rpmbuild command will generate the binary rpm in the rpmbuild/RPMS/platform_name_here directory.  In my case the directory is rpmbuild/RPMS/x86_64

To install the rpm binary simply issue the command:
# rpm -i binary_rpm_filename_here

No comments:

Post a Comment