Building SevenHats-based project

This article shows how to build a typical application based on SevenHats framework
A typical project based on SevenHats usually consists of several bundles. We are going to create the build for the first SevenHats tutorial application. It is organized as follows:

  • org.sevenhats.temperature. Exports some interfaces. It also uses logging bundle from SevenHats platform.
  • org.sevenhats.temperature.fahrenheit. Contains the implementations for the interfaces exported by org.sevenhats.temperature.
  • org.sevenhats.temperature.kelvin. Contains the implementations for the interfaces exported by org.sevenhats.temperature.
  • org.sevenhats.temperature.logging.config. Configures the SevenHats logging.

You can find the source code for these bundles at <SevenHats Home>/Projects/Tutorial1/code
SevenHats provides several ant tasks which can be used to build such project. We are going to use bundleCompile task to compile all the bundles. In fact, bundleCompile does the following things:

  • Checks if all the bundle dependencies can be resolved. At this stage all the bundles are taken account: those to be compiled and platform bundles.
  • Compiles the source code of every bundle and packs it into JAR. Each JAR is named after the appropriate bundle's symbolic name. So if bundle has the following entry in MANIFEST.MF:
Bundle-SymbolicName: org.sevenhats.temperature

then output JAR file will be named org.sevenhats.temperature.jar. (todo consider moving to Spring naming format http://www.springsource.com/repository/app/faq#q12 )

bundleCompile task requires several arguments. First of all, we need to define the bundles source code location in bundlesFolderPath attribute. This can be achieved by creating ant path element, which includes all the folders containing sources organized as follows:

  • <bundle source folder>/
    • src//this folder contains bundle sources
    • META-INF //this folder contains MANIFEST.MF file for this bundle

The second thing required for bundleCompile task is the ant path containing all the jars considered as 'platform' bundles. It is specified in platformFolderPath attribute.
destFolder attribute is used to specify the destination folder where newly packed JARs will be placed to. This folder will be created if it does not exist.
staticResources attribute define the ant pattern which specify the static resources to be copied from source folder to JAR.
There are also fork, target and debug attributes which can be specified for bundleCompile task, but they are pretty similar to the same attributes Javac ant task, so they don't need additional description.

Let us create the build file now.

builddemo.xml
<project name="Demo application build" default="compileBundles">

    <property name="lib.dir" location="${basedir}/lib"/>

    <path id="classpath">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
        </fileset>
    </path>

    <property name="destination.folder" value="${basedir}/output"/>
    <property name="platform.folder" value="${basedir}/../../../Framework/trunk/platform"/>
    <property name="sevenhats.bundles.folder" value="${basedir}/../../../build/scripts/output"/>
    <property name="demoapp.bundles.compile.folder" value="${basedir}/../code"/>


    <patternset id="resource.pattern">
        <include name="**/*.properties"/>
    </patternset>

    <path id="bundlesFolderPath">
        <dirset dir="${demoapp.bundles.compile.folder}">
            <include name="*"/>
        </dirset>
    </path>

    <path id="platformFolderPath">
        <fileset dir="${platform.folder}">
            <include name="*.jar"/>
        </fileset>
        <fileset dir="${platform.folder}">
            <include name="*.jar"/>
        </fileset>
    </path>

    <taskdef name="bundleCompile" classname="org.sevenhats.util.ant.BundleCompileTask" classpathref="classpath"/>

    <target name="compileBundles">
        <bundleCompile bundlesFolderPath="bundlesFolderPath" platformFolderPath="platformFolderPath"
                       destFolder="${destination.folder}" staticResources="resource.pattern" target="1.5" debug="true"
                       fork="true"/>
    </target>

</project>

Now, executing ant -f builddemo.xml command will lead to compiling and packing the bundles into four JARs: org.sevenhats.temperature.jar, org.sevenhats.temperature.kelvin.jar, org.sevenhats.temperature.fahrenheit.jar, org.sevenhats.temperature.logging.config.jar.

In the next part we are going to launch this application using some ant tasks.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.