Derby Hat

Building Derby





About This Document

These are the instructions for building the Derby jar files from the Derby sources.





Downloads

Before building Derby, you need to download the following:

Prerequisite Description
Derby Source If you are reading these instructions, chances are you have already unpacked a Derby source distribution. However, if you don't have the Derby source yet, get the development source tree from subversion by following these instructions.
Java Development Kit You need to install a Java 5 or later JDK. Probably, your machine already has this JDK. If not, Sun and IBM supply free JDKs for many machines.
Ant You need to install the Ant build tool, version 1.7.0 or higher. You can get Ant here.

If you are going to run the Derby tests, then you will need to download the JUnit test harness also:

Prerequisite Description
JUnit You need the JUnit test tool, version 3.8.2. The Ant build script will try to download JUnit for you automatically if it's missing. If this fails for some reason, you can download and install JUnit manually. You can get JUnit 3.8.2 here. Copy junit.jar into your Derby source tree, in the tools/java directory.





Simple Build

Before building Derby, cd to the root of your Derby source distribution. That is the top level directory which contains the LICENSE and NOTICE files. In addition, make sure that the version of Java which you are using is Java 5 or later. You can verify this by checking the output of the following command:


java -version

Now use the following Ant targets to build Derby.:

Target Description Command
clobber This target deletes all build artifacts.

ant -quiet clobber
buildsource This target compiles all source files needed for the Derby product. Don't be alarmed by all of the compiler warnings. We'll show you how to tidy those up later on.

ant -quiet buildsource
buildjars This target builds the Derby jar files.

ant -quiet buildjars

So, do this:


ant -quiet clobber
ant -quiet buildsource
ant -quiet buildjars

In order to build the Derby javadoc, you will need to run another target:

Target Description Command
javadoc This target builds the Derby javadoc. Be patient. The javadoc target takes a while.

ant -quiet javadoc


Verifying the Build

Run the sysinfo command to verify that the jars built correctly. This program will print out the Derby build information:


java -jar jars/sane/derbyrun.jar sysinfo

Testing Derby

If you want to build and run the Derby tests, make sure that you have downloaded the JUnit test framework. Then build all of the Derby sources, including the test classes:

Target Description Command
all This target compiles all Derby source files.

ant -quiet all

Putting all of this together, here's how you build the tests:


ant -quiet clobber
ant -quiet all
ant -quiet buildjars

To run the tests, consult the testing README.





Customized Build

You can customize the Derby build by setting variables in a file called ant.properties. The Ant tool looks for this file in your home directory. To find out where Ant thinks your home directory is, issue the following command and look for "user.home" in the output:


ant -diagnostics

Alternatively, or additionally, you can place properties in a file called 'local.properties' in the top of the source tree. Properties placed in this file have precedence over those in user.home/ant.properties.

Here are some Derby-specific variables which you may want to set in ant.properties:

Variable Description Default Example
deprecation Turn this flag off if you don't want to see pages of warnings generated when the compiler encounters references to deprecated methods.
on

deprecation=off
sane By default, this variable is set to true. This builds extra assertion and debugging logic into Derby classes. If you set this variable to false, then the Derby jar files will be smaller and Derby will run faster. During typical development, you will leave this variable set to true. However, this variable is set to false when building official Derby releases.
true

sane=false
junit Setting this property will overwrite the default location for junit.jar, used to build the tests. The default location is tools/java. If you set this property, the build will not automatically download junit.jar, and if it's not in the specified location, the build will stop.
tools/java/junit.jar

junit=/local0/junit.jar


Advanced Build

Derby is supposed to run in all of the following environments:

Platform JDBC Level
Java 7 JDBC 4.1
Java 6 JDBC 4.0
Java 5 JDBC 3
Small Device (CDC/FP 1.1) JSR169

The default Derby build does NOT necessarily verify that the compile-time contract is satisifed for any of these platforms. To get compile-time checks, you need to make sure that the following variables are set correctly. To see the values which the Derby build uses for these variables, build Derby after setting the following debug variable in your ant.properties:


printCompilerProperties=true

Here are the variables which determine whether the Derby build enforces compile-time contracts for the supported platforms:

Platform Compiler Variable Description Default Value
Java 7 java17compile.classpath The set of libraries in the Java 7 JDK. The build fails if your environment isn't a Java 5, 6 or 7 JDK. The set of system jars in your JDK if your environment is JDK 7. Otherwise, ${java16compile.classpath}
Java 6 java16compile.classpath The set of libraries in the Java 6 JDK. The build fails if your environment isn't a Java 5, 6 or 7 JDK. The set of system jars in your JDK if your environment is JDK 6. Otherwise, classes/stubs/jdbc4:${java15compile.classpath} if your environment is JDK 5. Otherwise ${java17compile.classpath}
Java 5 java15compile.classpath The set of libraries in the Java 5 JDK. The build fails if your environment isn't a Java 5, 6 or 7 JDK. The set of system jars in your JDK if your environment is JDK 5. Otherwise, classes/stubs/jdbc3:${java16compile.classpath}
Small Device (CDC/FP 1.1) jsr169compile.classpath This should be set to the list of small device libraries on your machine--if you have them. That is, the CDC/FP 1.1 jars and the jsr169 jar. To get a set of small device libraries, see Oracle's instructions or download IBM's WCTME 5.7. classes/stubs/jsr169:${java15compile.classpath}

The preceding variables are mandatory for the Derby build. You can also force the setting of the preceding variables by setting the following optional library variables in ant.properties:

Compiler Variable Description Default Value
j15lib If you set this variable to be the directory which contains your Java 5 jars, then the Derby build will set java15compile.classpath to be the list of jars in that directory. Optional variable. No default value.
j16lib If you set this variable to be the directory which contains your Java 6 jars, then the Derby build will set java16compile.classpath to be the list of jars in that directory. Optional variable. No default value.
j17lib If you set this variable to be the directory which contains your Java 7 jars, then the Derby build will set java17compile.classpath to be the list of jars in that directory. Optional variable. No default value.

Here, for instance, are some sample settings of classpath variables (you should omit the \ continuation markers, which are included in these examples simply to improve readability):


java16compile.classpath=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/charsets.jar: \
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/classes.jar: \
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/dt.jar: \
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/jce.jar: \
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/jconsole.jar: \
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/jsse.jar: \
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/laf.jar: \
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/management-agent: \
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/ui.jar

jsr169compile.classpath=/Users/myself/sw/phoneME/phoneme_advanced_mr2/lib/btclasses.zip: \
    /Users/myself/sw/phoneME/phoneme_advanced_mr2/lib/basis.jar: \
    /Users/myself/sw/jsr169Support/jdbc.jar