Chapter 23. JARs and Other Archives

Table of Contents

23.1. JAR-like Archives
23.2. WAR Files
23.3. EAR Files

Warning

Note that abuild's Java support is considered alpha as of version 1.0. Version 1.1 of abuild may include a Java solution that is not backward compatible with the solution in version 1.0.

In this example, we demonstrate how to create different types of archive types in Java. The actual contents of these archives are not necessarily valid for production, and these patterns do not necessarily reflect realistic dependencies among different archive types, but they do serve to illustrate how abuild handles different archive types in a fairly general way.

Note

Creation of Java archives is a weak point of abuild at this time. Suggestions about how to improve this are actively encouraged.

23.1. JAR-like Archives

In the doc/example/archive-types directory, you will find subdirectories for each of several archive types. Abuild knows how to create JAR files, WAR files, and EAR files. The names of the archives that abuild creates do not have to end with the suffix corresponding to the type. In particular, abuild is able to create JAR files that are not called *.jar as is necessary in some instances. When it does, it will also create a copy of that file whose name does end in .jar for compilation purposes as some versions of javac ignore classpath elements that are not either directories or files whose names end with .zip or .jar, a behavior that is consistent with the documentation.

Start by looking at the HAR example. If you study its Abuild-ant.properties file and its Abuild.interface file, you will observe that we are creating a HAR file here exactly the way we would create a JAR file except that we are using the .har suffix:

archive-types/har/Abuild-ant.properties

abuild.jar-name = har-example.har

archive-types/har/Abuild.interface

abuild.classpath = $(ABUILD_OUTPUT_DIR)/dist/har-example.har

Note that the HAR file created here probably wouldn't work as a HAR (hibernate archive) file. We're just naming it this way for purposes of illustration. If you needed to add other things to the HAR file, you would do so in the same way as you would for any other JAR file (adding to src/conf, src/resources, or their automatically generated counterparts as appropriate). Here are the contents of the HAR file:

example.har-contents.out

META-INF/
META-INF/MANIFEST.MF
com/
com/example/
com/example/har_example/
com/example/har_example/HarExample.class

Note that the META-INF directory and the MANIFEST.MF file are created automatically during the JAR creation process. Next, look at the JAR example. It is essentially identical to the HAR example except that this build item depends on har-example:

archive-types/jar/Abuild-ant.properties

abuild.jar-name = jar-example.jar

archive-types/jar/Abuild.interface

abuild.classpath = $(ABUILD_OUTPUT_DIR)/dist/jar-example.jar

The JarExample.java class imports a class defined in the HAR file to illustrate that it works in abuild to add a HAR file to the abuild.classpath variable even if it wouldn't work in straight ant. This is because abuild is creating a file whose ends with .har.jar and is adding that to the real classpath instead. Here are the contents of the JAR file:

example.jar-contents.out

META-INF/
META-INF/MANIFEST.MF
com/
com/example/
com/example/jar_example/
com/example/jar_example/JarExample.class