Tutorial09 Using Public Libraries

The set of tools available to the mxj programmer can be extended by using public libraries of code. The availability of free code is one of the Java platform's biggest strengths. With that in mind, the mxj API has been designed to make it as easy as possible to take advantage of other people's hard work.

Most libraries are distributed as .JAR files. For instance, to be able to use the net.mail.send and net.mail.recv objects, JavaMail must be installed. The current version of the library at the time of writing is 1.3.1. Note that one must also install the JavaBeans Activation Framework. After downloading and unarchiving the files, copy mail.jar and activation.jar to your java/lib directory. (Alternatively you could edit the max.java.config.txt file as described on the Configuring page.)

In addition to an assortment of readme and license files, many libraries come with API documentation generated by Java's javadoc utility. For JavaMail these docs are in the docs/Javadoc; they will be useful if you want to examine the code in net/mail/send.java or net/mail/recv.java. Note that to compile a class that refers to an external library you will have to modify your compiler's classpath to include the new .JAR file. So for instance if we're in the classes/net/mail directory, compilation of the net.mail.recv class can be accomplished with the following input at the command prompt:

javac -classpath "../../../lib/max.jar;../../../lib/mail.jar" recv.java