Installing Java-based FreeBSD ports

$Revision: 1.9 $ $Date: 2002/04/16 19:32:13 $ -- By Ernst de Haan (znerd@FreeBSD.org)

1. Introduction

1.1 Installation of Java-based ports

If a port uses the Java support in the FreeBSD Ports System, you should not have to worry about this as a system administrator. However, if necessary, there are options to influence the installation of Java-based ports.

It is possible to customize these port installations in the following ways:

A port that uses the Java support in the FreeBSD Ports system can be recognized by the fact that its Makefile at least sets USE_JAVA. Use a command like the following to find all of these ports:

find -X /usr/ports/ -name Makefile 2>/dev/null | xargs grep -l USE_JAVA

1.2 Global or local override

Overriding settings can either be done globally or it can be done for a specific port installation. If you override a setting globally, then this setting will be applied to the installations of all Java-based ports you add after your change.

A global override can be done by placing the setting in the /etc/make.conf file. This file serves as a central repository for make settings, global to your whole system. See the /etc/defaults/make.conf file for more details.

For example, to use the Sun JDK 1.4.x for Linux during all port installations from now on, put the following in your /etc/make.conf file:

JAVA_PORT= java/linux-jdk14

A local override overrides a setting for a single port installation only. This is done by adding the setting to the command line, in the form name=value.

For example:

# cd /usr/ports/www/jakarta-tomcat
# make JAVA_PORT=java/jdk13 install
This will attempt to build and install the Jakarta Tomcat port with the JDK 1.3.x for FreeBSD.

Note that the settings in /etc/make.conf take precedence over the settings on the command line!

2. Specifying a JDK

2.1 Introduction

By default, a Java-based port specifies in the Makefile what JDK it needs or would like to work with. It is generally not necessary to influence what JDK it chooses, although it is possible.

2.2 Changing the default behaviour

For a system administrator there are 4 ways to override the JDK a port should use:

The following table shows what settings are used to accomplish this:
Setting Description
JAVA_PORT The location of the Java port, relative to ${PORTSDIR} (typically /usr/ports).
Valid values are: java/jdk, java/jdk12-beta, java/jdk13, java/linux-jdk, java/linux-jdk13, java/linux-ibm-jdk13 and java/linux-jdk14.
JAVA_HOME The path for an installed JDK. This can be a path to any directory.
For example: /usr/local/linux-ibm-jdk1.3.1.

Use of JAVA_HOME is discouraged, because it interferes with the FreeBSD Ports dependency tracking system. Use JAVA_PORT instead, if possible.

2.3 Quircks

If JAVA_HOME is set, then it will take precedence over JAVA_PORT. Note that the port self may bind itself to a specific JDK.

3. Specifying the Java compiler

3.1 Default behaviour

Java-based ports typically use the default Java compiler that comes with a JDK (javac). There is an alternative Java compiler, called Jikes, that can be used instead of javac. If you have not installed Jikes, then by default Java-based ports will not use it either. However, if you have already installed Jikes, then they will by default make use of it.

3.2 Introduction to Jikes

Jikes is an open-source Java compiler by IBM, written in C++. It is typically magnitudes faster than the standard Java compiler that comes with a normal JDK, javac. The byte code produced by Jikes is generally better optimized than the byte code generated by javac. This is why Jikes is considered a better alternative by a lot of Java developers.

3.3 Changing behaviour

If you would like your Java-related ports to use Jikes, even if it is not installed yet, then either install it (from the port java/jikes) or set USE_JIKES to YES, either on the command line when installing the port or globally in your /etc/make.conf.

If you don't want ports to use Jikes as Java compiler, then either just don't install Jikes or explicitly set USE_JIKES to NO. There is a small difference between these 2 options. In the latter case, even ports that specify that they preferably are not built using Jikes will now use Jikes. And, even if Jikes gets installed on the system somehow, Jikes will not be used, unless the port overrides that setting.

If you don't want any of the Java-based ports you will install to use Jikes, then set USE_JIKES to NO in your /etc/make.conf, for example:

USE_JIKES=         NO

If only want this for a single port, then set it on the command line when installing that port, for example:

# make USE_JIKES=NO install

Summarizing, these are the possible settings for USE_JIKES:

Setting Description
undefined Jikes will not be used if it is not already installed, otherwise it will be. This may be overridden by the port.
NO Jikes will not be used, unless the port overrides this setting.
YES Jikes will be used, unless the port overrides this setting.