Sun GlassFish Enterprise Server

# Java BluePrints Build System

Java BluePrints Build system is a collection of build scripts based on Ant. It provides for building, packaging, deploying and running different types of Java EE modules, including `.ejb`, `.war`, `.ear`, `.rar`, and `.par` files.

## Build Environment

If you have not already done so, follow the instructions in the Required Software section of the Java EE 6 Tutorial to download and install the following:

- Java Platform, Standard Edition 6 Development Kit (JDK 6)
- Java Platform, Enterprise Edition 6 Software Development Kit (Java EE 6 SDK)
- Apache Ant 1.7.1
- Java EE 6 Tutorial Component
- NetBeans IDE (optional)

Read the remainder of the Using the Tutorial Examples chapter of the Tutorial for more information on setting up your environment to run the examples.

## Ant Targets

Some commonly used Ant targets are as follows:

      check                        verifies the build setup that is common for all modules
      clean                        removes the generated directories, such as build and dist
      compile                      compiles the project
      create-javamail-resource     creates a JavaMail resource
      create-jdbc-connection-pool  creates a JDBC connection pool
      create-jdbc-resource         creates a JDBC resource
      create-jms-connection        creates a JMS connection factory
      create-jms-resource          creates a JMS resource
      create-persistence-resource  creates a persistence resource
      default                      compiles and packages the archive
      delete-javamail-resource     deletes a JavaMail resource
      delete-jdbc-connection-pool  deletes a JDBC connection pool
      delete-jdbc-resource         deletes a JDBC resource
      delete-jms-resource          deletes a JMS resource
      delete-persistence-resource  deletes a persistence resource
      deploy                       deploys the application
      keydel_common                deletes a file-realm user
      keygen_common                creates a file-realm user
      launch                       launches the application in a browser
      listJmsDestinations          lists JMS destinations
      package                      packages the archive
      package-persistence-unit     packages the persistence archive
      reconfig                     reconfigures the application server
      run                          builds, packages and runs the application
      runjavaclient                run stand-alone Java client
      start-db                     starts the database server
      stop-db                      stops the database server
      undeploy                     undeploys the application

The following targets provide sample application-specific behavior.

      -post-compile
      -pre-clean
      -pre-compile
      -pre-deploy
      -pre-setup

## Java EE Modules/Applications

Using the above targets it is possible to build and run the following types of Java EE modules and applications:

`.ear`
  Application Archive
`.jar`
  EJB Module
`.war`
  Web Module
`.rar`
  Connector Module
`.par`
  Persistence Archive
`.jar`
  Application Client Archive

## Sample Build Files

### Application Project

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="duke-stateful-ear" default="ear" basedir=".">

        <property name="is.ear.module" value="true"/>

        <path id="ear-components">
            <filelist dir="./duke-stateful-ejb" files="build.xml"/>
            <filelist dir="./duke-stateful-appclient" files="build.xml"/>
            <filelist dir="./test" files="build.xml"/>
        </path>

        <import file="../../bp-project/main.xml"/>

        <target name="all" depends="ear,deploy,client-stubs">
            <antcall target="run"/>
        </target>

        <target name="run">
            <subant target="run-app-client">
                <fileset dir="duke-stateful-appclient" includes="build.xml"/>
            </subant>
        </target>

    </project>

### EJB Jar Project

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="hello-stateless-ejb" default="default" basedir=".">

        <property name="is.ejb-jar.module" value="true"/>

        <import file="../../bp-project/main.xml"/>

        <target name="all" depends="default,deploy">
            <subant target="default">
                <fileset dir="test" includes="build.xml"/>
            </subant>
            <antcall target="run"/>
        </target>

        <target name="run">
            <subant target="runtest">
                <fileset dir="test" includes="build.xml"/>
            </subant>
        </target>
    </project>

### Web Project

`<?xml version="1.0"` `encoding="UTF-8"``?>`
`<project name="bp-web-project" default="default" basedir=".">`
`<property name="is.war.module" value="true"/>`
`<import file="bp-project/main.xml"/>`
`</project>`

### Java Persistence Unit Project

`<?xml version="1.0"` `encoding="UTF-8"``?>`
`<project name="hello-pu" default="default" basedir=".">`
`<description>Builds, tests, and runs the project hello-pu.</description>`
`<property name="is.jar.module" value="true"/>`
`<property name="is.persistence-unit.module" value="true"/>`
`<import file="../../setup/main.xml"/>`
`</project>`

### Web Project That Depends on the Above Java Persistence Unit Project

`<?xml version="1.0" encoding="UTF-8"?>`
`<project name="hello-servlet" default="default" basedir=".">`
``
`<property name="is.war.module" value="true"/>`
``
`<!-- This project is dependent on the hello-pu project so it is declaring a dependency -->`
`<property name="hello-pu.home" value="${home.dir}/../hello-pu"/>`
``
`<!-- extra.classpath property adds to the classpath used for compilation -->`
`<property name="extra.classpath" value="${hello-pu.home}/dist/hello-pu.jar"/>`
``
`<!-- include the persistence unit in the Web-app -->`
`<target name="-post-compile" depends="init">`
`<copy file="${hello-pu.home}/dist/hello-pu.jar" todir="${build.dir}/web/WEB-INF/lib"/>`
`</target>`
``
```<!-- Note that this project is sharing the build system with other projects -->`
`<import file="../../bp-project/main.xml"/>`
```</project>`

### Web Project That Depends on a JSF Component Library

`<?xml version="1.0"?>`
`<project name="bp-slider-navigator" default="default" basedir=".">`
``
`<property name="is.war.module" value="true"/>`
```<import file="../../../bp-project/main.xml"/>`
``
```<property name="project.ui" value="../../../components/ui"/>`
`<property name="reference.ui.jar" value="${project.ui}/dist/ui.jar"/>`
``
`<target name="-pre-compile" depends="init">`
`<copy file="${reference.ui.jar}" todir="${build.web.dir}/WEB-INF/lib"/>`
`</target>`
`</project>`

Copyright © 2010 Sun Microsystems, Inc. All rights reserved.