Translation(s): English ~ espaƱol

Introduction

In addition to the normal debhelper packaging tools there are some additional tools specifically for dealing with Java packages. Javahelper for packages without sane build systems and in combination with build systems to make them Debian compliant, maven-repo-helper for adding Maven artifacts to a non-Maven package, maven-debian-helper as the primary helper tool for any Maven project and gradle-debian-helper for Gradle-based projects. This page will inform you about common Java packaging workflows in Debian and point you to real-life examples which can be used as a starting point for your own packages.

Java Policy

Java packages in Debian abide like all other packages by the Debian Policy. Java-specific Policy elements are documented in the Debian policy for Java.

Javahelper

Javahelper is documented in the javahelper package in /usr/share/doc/javahelper/tutorial.txt.gz, also replicated here.

In addition to the tutorial, a talk was given at DebConf10 covering the use of javahelper. The talk is available as:

The idea behind javahelper is that most Java packages should be trivial. The integration with debhelper and the dh sequencer means that you shouldn't need anything in debian/rules, just a few files under the debian directory.

Using javahelper and DH7 ideally your rules file will look like this:

JAVA_HOME=/usr/lib/jvm/default-java

%:
        dh $@ --with javahelper

All of the work is done by javahelper working from other files under debian/.

Java compilation 1x1

This section explains the basic terms and methods to compile Java source files into bytecode and the creation of jar files.

No build system

There are some upstream projects that don't provide a proper build system. In some cases it is useful to download source packages from Maven Central and in those cases they also come with no build system, just source code. For all those reasons Javahelper is the perfect tool to compile the code and create a proper Debian package.

Build systems

There are a few build systems in use by Java programs.

Ant

If your package uses Ant then DH7 should automatically detect the build.xml and call things appropriately.

Maven

Use maven-debian-helper for standard Maven projects, use maven-repo-helper and maven-ant-helper to fallback the build to Ant - usefull mostly for building a library which is part of the Build-Depends of Maven itself.

Gradle

Use gradle-debian-helper. Gradle is a flexible project so you may need to patch the build scripts anyway. This helper is currently in early stage so if you do not want to use it, you can follow the example of Gradle itself, or from the list of packages using gradle as mentioned here.