This page documents an idea on how to improve the java alternatives system.

Problem

All java related tools such as java, javac, javadoc are symlinks are handled by the alternatives system. Neither the non-privileged user nor the Debian packager can easily override which JVM should be used. There is some support for overriding in the java-wrappers package but the implementation is not very Debianish. That is why we will introduce sensible tools to the java-common package.

Use Cases

Basic Usage

sensible-java or sensible-javac will just run java and javac by default but you can change it by specifying JAVA_HOME:

JAVA_HOME=/usr/lib/jvm/default-java
export JAVA_HOME
sensible-java ...

You get more flexibility with JAVA_HOME_DIRS:

JAVA_HOME_DIRS="/usr/lib/jvm/default-java /usr/lib/jvm/java-6-sun"
export JAVA_HOME_DIRS
sensible-jar ...

or even better with JAVA_FLAVOR:

JAVA_FLAVOR="sun local"
export JAVA_FLAVOR
sensible-javadoc ...

JAVA_HOME has priority over JAVA_HOME_DIRS which has priority over JAVA_FLAVOR. Some examples for JAVA_FLAVOR are:

The complete list can be found in /etc/java/jvm.list and will be documented later.

Setting up CLASSPATH

The contruction of the CLASSPATH can be simplified by specifying

DEB_JARS="item1 item2 item3"

where each item can be

The .jar extension is optional for filenames and will be added automatically. All JAR files will be added to the CLASSPATH in lexical order for the directory case. An explicitely specified CLASSPATH has priority over DEB_JARS.

Advanced Usage

The program sensible-java-home can be used to improve existing shell wrappers. Just add a line like

JAVA_FLAVOR=default
DEB_JARS="hello-impl hello-api"
export JAVA_FLAVOR DEB_JARS
eval $(sensible-java-home java javac javadoc)

to the top of the wrapper. That will insert the following code into the wrapper:

JAVA_HOME=/usr/lib/jvm/default-java
JAVA_CMD=/usr/lib/jvm/default-java/bin/java
JAVAC_CMD=/usr/lib/jvm/default-java/bin/javac
JAVADOC_CMD=/usr/lib/jvm/default-java/bin/javadoc
CLASSPATH=/usr/share/java/hello-impl:/usr/share/java/hello-api
export JAVA_HOME JAVA_CMD JAVAC_CMD JAVADOC_CMD CLASSPATH

The arguments to sensible-java-home are optional and default to java.

Ant Support

The line

eval $(sensible-java-home java javac)

will be added to the ant wrapper and allows you to set JAVA_FLAVOR and DEB_JARS before calling ant.

Makefile Usage

You can pimp up debian/rules this way:

export JAVA_FLAVOR = default
export DEB_JARS = hello-impl hello-api

build-indep:
        sensible-javac ...
        ant

Implementation Details

The individual sensible commands will be simple symlinks to sensible-java-home which will be implemented in dash compatible shell scripts. Unit tests might use something more advanced like python doctests. An environment variable JAVA_DEBUG will enable debugging output.


CategoryJava