<code>build-classpath</code> is a script that can be used to generate classpaths from generic names of JAR files. Example:

+

When package needs to have additional dependencies in CLASSPATH packager '''SHOULD''' use build-classpath or build-jar-repository commands to modify CLASSPATH instead of manually specifying path to JAR files of dependencies.

Introduction

This page represents Fedora guidelines for packaging libraries and applications written in Java and related languages using Java Virtual Machine as bytecode interpreter. It DOES NOT aim to extensively describe packaging techniques and tips. RPM macros and commands used here are documented in man pages. Furthermore a separate Java Packaging HOWTO describes Java packaging techniques in detail and includes examples, templates and documentation aimed at packagers and Java developers who are taking their first steps in Java RPM packaging.

Java Packaging

Fedora Java packaging is originally based on JPackage Project standards. Over time we have diverged in packaging tools in most areas but we mostly keep backward compatibility with older packages that make use of JPackage standards.

Release tags

JAR file installation

The following applies to all JAR files except JNI-using JAR files and application-specific JAR files (ie. JAR files that can only reasonably be used as part of an application and therefore constitute application-private data).

Split JAR files

If a project offers the choice of packaging it as a single monolithic JAR or several ones, the split packaging SHOULD be preferred.

Filenames

If the package provides a single JAR file installed filename SHOULD be %{name}.jar.

If the package provides multiple JAR file, files SHOULD be installed in a %{name} subdirectory

Versioned JAR files (*-%{version}.jar) MUST NOT be installed unless the package is a compatibility package

Packages CAN provide alternative filenames as long as they do not conflict with other packages

NoteHere %{name} refers either to package name, or name of subpackage where the jar is installed.

Installation directory

All architecture-independent JAR files MUST go into %{_javadir} or a Java-version specific directory %{_javadir}-* as appropriate[1]. Packages CAN place JAR files into subdirectories.

Compatibility packages

In certain cases it might be necessary to create compatibility packages that provide older API/ABI level of the same library. However creating these compatibility packages is strongly discouraged. To standardize and simplify packaging of such compatibility packages following rules apply:

Compatibility packages are named in the same way as original except addition of version to package name,

Any JAR or POM files MUST be versioned.

Ant and Maven compatibilitybuild-classpath and related tools will resolve versioned jar files if versioned jar is asked for. Maven will use dependency information will return versioned jar if it matches the version asked for in the pom file.

Javadoc installation

Java API documentation uses a system known as Javadoc. All javadocs MUST be created and installed into a directory of %{_javadocdir}/%{name}.

Directory or symlink %{_javadocdir}/%{name}-%{version}SHOULD NOT exist.

The javadoc subpackage MUST be declared noarch even if main package is architecture specific.

BuildRequires and Requires

Java packages MUST BuildRequire their respective build system:

BuildRequires: maven-local for packages built with Maven

BuildRequires: ant for packages built with ant

BuildRequires: java-devel for packages built with javac

BuildRequires: gradle for packages built with gradle

Java binary packages MUST have transitive Requires on:

java-headless or java-headless >= 1:minimal_required_version

jpackage-utils

If Java package needs sound or graphical server connection it MUST have non-transitive Requires:

java or java >= 1:minimal_required_version

CLASSPATH modification

When package needs to have additional dependencies in CLASSPATH packager SHOULD use build-classpath or build-jar-repository commands to modify CLASSPATH instead of manually specifying path to JAR files of dependencies.

Maven pom.xml files

If upstream project is shipping Maven pom.xml files, these MUST be installed. Additionally package MUST install mapping between upstream artifact and filesystem in one of following ways:

By using %mvn_build and %mvn_install macros when building with Maven

By using %add_maven_depmap macros when building with Ant or other buildsystems

Additional documentationUsage of %add_maven_depmap macro is documented in detail in Java Packaging HOWTO.

Wrapper Scripts

Applications wishing to provide a convenient method of execution SHOULD provide a wrapper script in %{_bindir}.

The jpackage-utils package contains a convenience %jpackage_script macro that can be used to create scripts that work for the majority of packages. See its definition and documentation in /etc/rpm/macros.jpackage. One thing to pay attention to is the 6th argument to it - whether to prefer a JRE over a full SDK when looking up a JVM to invoke - most packages that don't require the full Java SDK will want to set that to true to avoid unexpected results when looking up a JVM when some of the installed JRE's don't have the corresponding SDK (*-devel package) installed.

The previous example installs the "msv" script (5th argument) with main class being com.sun.msv.driver.textui.Driver (1st argument). No optional flags (2nd argument) or options (3rd argument) are used. This script will add several libraries to classpath before executing main class (4th argument, jars separated with ":"). build-classpath is run on every part of 4th argument to create full classpaths.

Packages using APIs

Packaging JAR files that use JNI

Applicability

Java programs that wish to make calls into native libraries do so via the Java Native Interface (JNI). A Java package uses JNI if it contains a .so file. Note that this file can be embedded within JAR files themselves.

Note that GCJ packages contain .sos in %{_libdir}/gcj/%{name} but they are not JNI .sos.

Guideline

JAR files using JNI or containing JNI shared objects themselves MUST be placed in %{_jnidir} and CAN BE symlinked to %{_libdir}/%{name}.

JNI shared objects MUST be placed in %{_libdir}/%{name}

NoteIf the JNI-using code calls System.loadLibrary you'll have to patch it to use System.load, passing it the full path to the dynamic shared object.

Macro expansions%{_jnidir} usually expands into %{_prefix}/lib/java. %{_prefix}/lib64/java will cease its existence and will be decomissioned

Example

To satisfy this Fedora requirement of using "System.load()" instead of "System.loadLibrary()" while still providing 32-bit versus 64-bit usability as well as complying with Java's write-once-run-anywhere goal, most JNI jar file should contain code similar to the following (as used in the pki-symkey JNI package):

Packages utilizing approach of bundling so files as resources within JAR files themselves do not have these issues and are more self-contained.

Notes on multiarch

Our guidelines have never been completely multiarch-aware. So it was never really possible to install both i686 and x86_64 JNI-using java libraries. However guidelines complicated things by introducing usage of %{_libdir} and other directories. This version makes it clear we do not support multiarch for JNI-using packages.

Some of the complications with multiarch for JNI packages are:

build-classpath and related tools would need to be aware what will be architecture of executing JVM

build-jar-classpath would still not work for creating symlinks because it would create them on build architecture instead of runtime architecture

Previous reasons cause creating of /usr/bin wrappers impractical

Handling proper requires in RPM is impossible. For example package Z-native.i686 and JDK.x86_64 are installed. As far as RPM is concerned this would be enough to provide Z.noarch with needed "Requires: Z-native", but it would not work during runtime.

Things to avoid

Pre-built JAR files / Other bundled software

Many Java projects re-ship their dependencies in their own releases. This is unacceptable in Fedora. All packages MUST be built from source and MUST enumerate their dependencies with Requires. They MUST NOT build against or re-ship the pre-included JAR files but instead symlink out to the JAR files provided by dependencies. There may arise rare cases that an upstream project is distributing JAR files that are actually not re-distributable
by Fedora. In this situation, the JAR files themselves should not be redistributed -- even in the source zip. A modified source zip should be created with some sort of modifier in the name (ex. -CLEAN) along with instructions for reproducing. It is a good idea to have something similar to the following at the end of %prep (courtesy David Walluck):