When unzipped, the examples will create a directory whose contents look like this:
build.xml my.ant.properties.win classes/ src/ jars/
build.xml is the build file for Ant, the de facto standard for building Java projects. You don’t have to use Ant, but considering the classpath challenges in dealing with Java builds, particularly with QTJ (see Chapter 1), you’ll probably find it well worth your while. If you don’t already have it, you can get Ant from http://ant.apache.org/, and you can learn more in Ant: The Definitive Guide (O’Reilly).
Tip
The classes and jars directories are created by Ant, and will not be present when you first unzip the archive.
Using the command line, type ant
in this directory
to run the default target. In this case, it’s the
help message:
cadamson% ant Buildfile: build.xml help: [echo] Available targets: [echo] ch0n -- compile source for chapter n (eg "ch01", "ch02", etc.) [echo] all -- compile source for all chapters [echo] ch0n.jar -- make a .jar file for chapter n [echo] qtj-notebook.jar -- compile source for all chapters and make jar [echo] all.jar -- synonym for qtj-notebook.jar [echo] run-example -- compile and run "example" [echo] help-names -- echo all example names for use with run-example [echo] clean -- remove .class files [echo] help -- this help message (default) [echo] BUILD SUCCESSFUL Total time: 2 seconds
You can look in the build.xml file for more information. One important note is that compiling requires the path to the QTJava.zip file, as described in Chapter 1. The default is the Mac OS X path, /System/Library/Java/Extensions/QTJava.zip. If you’re using Windows, you need to override this. The provided file my.ant.properties.win has a sample path that looks like this:
qtjavazip.file=c:\\Progra~1\\Java\\j2re1.4.2\\lib\\ext\\QTJava.zip
Edit this so that it refers to the path to
QTJava.zip on your system, and then rename the
file to my.ant.properties, so
build.xml will pick it up. Because any Ant
properties are picked up from this file, it also gives you the
opportunity to make other Ant tweaks, such as repointing
jvm.home
to use one of several Java installations
on your box, or to change the java.compiler
to
jikes
.
To compile all the book examples into a JAR file, type:
ant qtj-notebook.jar
This will produce output like the following:
cadamson% ant qtj-notebook.jar Buildfile: build.xml init: [echo] qtjavazip.file = /System/Library/Java/Extensions/QTJava.zip all: [javac] Compiling 53 source files to /Users/cadamson/Documents/ O'Reilly/books/qtj developer's notebook/code/classes qtj-notebook.jar: [jar] Building jar: /Users/cadamson/Documents/O'Reilly/books/qtj developer's notebook/code/jars/qtj-notebook.jar BUILD SUCCESSFUL Total time: 7 seconds
You can then run any of the examples by extending the classpath to include the qtj-notebook.jar file, as in:
java -cp jars/qtj-notebook.jar com.oreilly.qtjnotebook.ch02.SimpleQTPlayer
There are also Ant targets to compile and run every example in the
book. Use ant help-examples
to see a list of
example names.
Get QuickTime for Java: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.