Java/Packaging/Overview
From openSUSE
Contents |
Java Packaging Tutorial
This is a step by step introduction on how to build software packages of Java programs for openSUSE and others using the openSUSE Build Service.
First steps : Get prepared
- Register your Build Service account.
- Become familiar with the Build Service web application.
- Add the openSUSE Tools repository and install osc.
- Add the repositories that you want to build for. A good starting point is 'openSUSE 10.3'. We will leave cross-platform package building for an advanced tutorial.
- Add a package in the build service for the software you want to package.
- 'Name' is how the package should be named, eg ultimatesoftware.rpm.
- 'Title' is the short description visible in YaST Software Management's package list.
- 'Description' is the long description shown separately.
- Tick the box 'Create RPM SPEC file template' to get SPEC file template. You can use it later as a starting point.
Get source and patch files
- add the tarball containing the source code of your program to the project using [add file]. The source code archive can be uploaded from a local computer or directly from the project homepage by specifying the URI.
Work on the Specfile
A template spec-file is already created for you and added as <packagename>.spec to your project. If there is an existing spec file already, you can use this by adding it to the project files.
Building the package
It is advised, to do a local build first and check if everything is working. You also get an immediate feedback if the build fails (what will certainly happen at the first try). Once the package is building locally, you then update your openSUSE build project folder with all the changes.
- Local build
osc build openSUSE_10.3 ARCH <packagename>.spec
once this is successful, commit the changes to your project folder with
osc commit
then go to the website and mark the package for rebuild. There will be a feedback in you package folder if the build was successful.
A Sun Java
The Sun Java is not available in standard repository, so you must add the NonFree repository, which contains the Sun JDK. Just type
osc meta prj [your project] -e
and add the repository
<repository name="openSUSE_10.3">
<path project="openSUSE:10.3" repository="standard"/>
<!-- the NonFree repository -->
<path project="openSUSE:10.3:NonFree" repository="standard"/>
...
BuildRequires
java-devel- a preffered symbol. But in BuildService this symbol is often expanded to opensource Java (eg. gcj), which needs some adjustments in build.java-1_5_0-sun-devel- an explicit require of Sun compiler. This option produce less errors, because the majority of developers use this JDK. This option needs to add a NonFree repository (see above)java-1_7_0-icedtea- in Factory is available an IcedTea Java, which is GPL version of Sun Java.
Example
We use as an example columba, an eMail client completely written in Java. An example spec-file can be seen below.
Work on SPEC-file
columba.spec
Name: columba
Summary: eMail client written in Java
Version: 1.4
Release: 1
License: GPL
Group: Productivity/Networking/Email/Clients
Source0: %{name}-%{version}-src.zip
URL: http://www.columbamail.org
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Autoreqprov: on
BuildRequires: unzip
BuildRequires: update-alternatives, java-1_5_0-sun-devel
BuildRequires: ant
Requires: java >= 1.5.0
BuildArch: noarch
%description
Columba is an Email Client written in Java, featuring a user-friendly
graphical interface with wizards and internationalization support. Its
a powerful email management tool with features to enhance your
productivity and communication.
So, take control of your email before it takes control of you!
Feature Highlights
* Clean and Response User Interface
* Cross Platform
* Internationalization
* Unlimited Functionality using Plugins
* Safe and Secure
* Glueing together Third-Party Tools
* Multiple Accounts and Profiles
%prep
rm -rf $RPM_BUILD_ROOT
%setup -q -n %{name}-%{version}-src
%build
%ant jar
%install
rm -rf $RPM_BUILD_ROOT
# jars
install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/%{name}
install -m 755 %{name}.jar $RPM_BUILD_ROOT%{_datadir}/%{name}/
# lib
#install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/%{name}/lib/jpa
#install -m 755 lib/jpa/* $RPM_BUILD_ROOT%{_datadir}/%{name}/lib/
cp -rp lib $RPM_BUILD_ROOT%{_datadir}/%{name}/
install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/%{name}/native/linux
cp -rp native/linux $RPM_BUILD_ROOT%{_datadir}/%{name}/native/
install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/%{name}/plugins
cp -rp plugins/* $RPM_BUILD_ROOT%{_datadir}/%{name}/plugins/
# startscript
cat > %{name} << EOF
#!/bin/sh
java -jar %{_datadir}/%{name}/%{name}.jar
EOF
install -d -m 755 $RPM_BUILD_ROOT%{_bindir}
install -m 755 %{name} $RPM_BUILD_ROOT%{_bindir}/
%clean
rm -rf $RPM_BUILD_ROOT
%files
# %defattr(-, root, root)
%doc AUTHORS CHANGES LICENSE README
%{_bindir}/*
%{_datadir}/%{name}/*
%changelog -n %{name}
* Wed Nov 14 2007 - PACKAGERNAME@opensuse.org
- initial RPM for columba on openSUSE
Building it
We use the osc tool to perform a local build now, as repeated builds to correct errors go faster when using --noinit.
osc build openSUSE_10.3 x86_64 columba.specOnce the package builds, we check it into the buildservice with
osc commit

