Issues while packaging java app with rpmbuild...
Panu Matilainen
pmatilai at laiskiainen.org
Sun Oct 26 09:06:34 UTC 2008
On Fri, 17 Oct 2008, Ann Basso wrote:
> I am trying to package a java application into an RPM. I have gone through
> several tutorials and I am also able to make an RPM but there are some issue
> with it that I am unable to figure out.
> Basically, the java app consists of a couple of jars, a property file, and a
> shell script to trigger the app. jars are generated by ant.
> Now, even after reading so much about rpm spec files, I am totally confused
> about the following things -
>
> 1. Where should I put my jars and other files? rpm/SOURCES or rpm/BUILD?
> Since my jars are already ready (created by ant) I don't want to do anything
> in "build" section. There is nothing to build. Right?
Since you're packaging things that are already "built", then yes there's
nothing to build. You still want to treat the jars and such as
sources to be able to create a src.rpm of the thing and to avoid
hardcoding paths to your own setup etc.
So you'd have something like
SOURCE0: myapp-1.jar
SOURCE1: myapp-2.jar
SOURCE2: myapp.sh
> 2. What should I do in "Install" section? I would like to have the user
> install the application (i.e. the jars) in /home/username/javaapps/myapp.
> Should I actually install (i.e. just create this directory structure
> /home/annb/javaapps/myapp) or should I create this dir structure under
> Install?
Putting things into users' home directory is not going to work well and
goes against the ideas of rpm. Install the app into a system-wide
location, such as %{_libdir}/myapp for the jars and other misc bits and
%{_bindir}/myapp for the launcher script.
Assuming the example SOURCE's from above, you'd have something like:
%install
mkdir -p $RPM_BUILD_ROOT%{_bindir} $RPM_BUILD_ROOT%{_libdir}
install -m 644 %{SOURCE0} %{SOURCE1} $RPM_BUILD_ROOT%{_libdir}/
install -m 755 %{SOURCE2} $RPM_BUILD_ROOT%{_bindir}/
For this to work you'll need to set BuildRoot in your spec (you'll always
want to have it anyway), something like this'll do:
BuildRoot: %{_tmppath}/%{name}-%{version}
> 3. what should go in the files section? As I understand, all the files that
> I want in the rpm should be listed here. But I am totally lost about from
> where should I pick the files? From BUILD or from INSTALL?
%install is used to put the results to a directory tree (again, you'll
want the buildroot in your spec)
> 4. This is what I have in my spec file. (Shown below). When it creates an
> rpm, the rpm contains the hardcoded directoty structure i.e. /home/annb/...
> Please help. I am really tired of this now.
>
> [code]
> %define _prefix /home/robert/javaapps
> %define name PCMonitor
> %define summary PC Monitor
> %define version 1
> %define release 1
> %define license GPL
> %define group Development/Languages
> %define source http://none.net
> %define url http://none.net
> %define vendor None
> %define packager Ann B
While defining name, version etc this way isn't "wrong", it's unnecessary
and redundant, see below.
>
> Name: %{name}
> Version: %{version}
> Release: %{release}
> Packager: %{packager}
> Vendor: %{vendor}
> License: %{license}
> Summary: %{summary}
> Group: %{group}
> Source: %{source}
> URL: %{url}
> Prefix: %{_prefix}
> BuildArchitectures: noarch
>
> %description
> PC Monitor
> %prep
> %build
> cp -r %{_topdir}/SOURCES/* %{_topdir}/BUILD/pcmonitor
> %install
> cp -r %{_topdir}/BUILD/* %{_prefix}/pcmonitor
Never blindly copy what's in build or sources directories, you don't know
what other packages have their sources and builds in there (eg on my
system, this is gigabytes of stuff)
> %clean
> %files
> %{_prefix}/pcmonitor
Try something like this:
---
Name: PCMonitor
Release: 1
License: GPL
Summary: PC Monitor
Group: Development/Languages
Source0: pcmonitor.jar
Source1: pcmonitor-util.jar
Source2: pcmonitor.sh
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}
%description
PC Monitor
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
mkdir -p $RPM_BUILD_ROOT/%{_libdir}/pcmonitor
install -m 644 %{SOURCE0} %{SOURCE1} $RPM_BUILD_ROOT%{_libdir}/pcmonitor
install -m 755 %{SOURCE2} $RPM_BUILD_ROOT%{_bindir}/
%clean
rm -rf $RPM_BUILD_ROOT
%files
%{_bindir}/pcmonitor.sh
%{_libdir}/pcmonitor
---
I don't know the names of your jar files and scripts so you'll need to
adjust them, and probably you need to adjust the launcher script to take
into account that the location of jar's which is not your home directory
anymore etc.
- Panu -
More information about the Rpm-list
mailing list