Fink:Policy:Packaging Java

From the Fink Wiki
Jump to: navigation, search


There is no official "policy" per se for packaging Java software in Fink, but there are a number of best practices that make it easier.

The Type Field

By default, if you use Type: java without specifying a version, Fink will use the lowest JDK found in /System/Library/Frameworks/JavaVM.framework/Versions. So if you have a 1.3.1, 1.4.2, and 1.5.0 JDK on your system, it will use the 1.3.1.

If you use Type: java(version) (i.e., Type: java(1.4)), it will use the highest JDK found that matches that version. So if you have both a 1.4.1 and 1.4.2 JDK on your system, it will use the 1.4.2 JDK.

Regardless of whether you use the versioned or unversioned field, as long as you're setting Type: java, the build environment inside your package will have the following extra environment variables set:

 JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/detected_version/Home
 PATH      /System/Library/Frameworks/JavaVM.framework/Versions/detected_version/Home/bin:$PATH

Using the Type Field Effectively

There are 2 major ways it is recommended to package Java software, depending on whether you want to require a specific JDK, or you want to target a specific JDK or higher.

Requiring a Specific JDK

If you want to ensure your software is compiled with, say, the 1.4 JDK, use:

 Type: java(1.4)

This will detect a JDK of that specific major and minor version number, and set JAVA_HOME and PATH respectively. If the software you are packaging uses javac -target (or ant's <javac target=""/> notation), it will still use the JDK that you specified, but generate bytecode compatible with the target given.

Using The Available JDK (recommended)

The problem with using Type: java(1.4) is that it requires a specific JDK, even if later ones are available. The primary reason to do so is to be able to create bytecode usable by older JDKs.

Instead, it is recommended to do the following:

 Package: myjavapackage
 Type: java
 Depends: system-java (>= 1.4-1)
 BuildDepends: system-java-dev (>= 1.4-1)
 Patch: %n.patch

Create a patch that makes sure that javac is being called with a target of 1.4. In the case of an ant build.xml, change any entries like:

 <javac srcdir="foo">
   <patternset refid="foo.files" />
 </javac>

...into...

 <javac target="1.4" srcdir="foo">
   <patternset refid="foo.files" />
 </javac>

In the case of some other tool calling javac, you can pass "-target" on the javac command-line.

This lets you not care what JDK is installed, as long as it's 1.4 or newer.

Problems with specific JDKs

as of release 1.5, 'enum' is a keyword, and may not be used as an identifier 
The 1.5 JDK adds some new keywords to the language, like enum. In some cases, you might need to add source="1.4" to your build.xml (or -source 1.4 on the javac command-line) to make things work correctly.