Java EE 6 SDK

# Common Build Instructions for Sample Applications

The sample applications depend on the following software:

- Java SE Development Kit (JDK) version 1.6.0_16.
- The Java Blueprints build system included in the Java EE SDK, which in turn depends on Apache Ant version 1.7.1.
- The Java DB database included in the Java EE SDK.

Due to these dependencies, you must perform some one-time setup tasks before building and running the individual samples.

### One-Time Setup Tasks

Note: In the following instructions, `<javee.home>` refers to the directory where the Java EE SDK is installed; for example, `C:\glassfish3`.

1. Download and install JDK version 1.6.0_16, if necessary.

   If JDK version 1.6.0_16 is not already on your system, you must download and install it. The download is available at the Java SE Downloads page.

2. Download and install Apache Ant version 1.7.1, if necessary.

   If Apache Ant version 1.7.1 is not already installed on your system, you can download and install it as an add-on using the Update Tool utility included in the Java EE SDK. For instructions about using Update Tool, see Extending Enterprise Server in Sun GlassFish Enterprise Server v3 Administration Guide.

3. Configure the Java Blueprints build system.

   The configuration file for the Java Blueprints build system used by the samples is:

   `<javee.home>/samples/bp-project/build.properties`.

   Edit the properties in this file to reflect your installation:

   Property Name | Description | Examples
   --- | --- | ---
   `javaee.home` | The directory where the Java EE 6 SDK/application server is installed. | `C:\glassfish3`
   `javaee.server.name` | Host name of system where Java EE 6 SDK/application server is installed. | `localhost`
   `javaee.server.port` | The port number of the application server. | `8080`
   `javaee.server.username` | The administrator username specified for the application server. If no username is specified, use the value `anonymous`. | `admin`
   `javaee.server.passwordfile` | The path to a file containing the admin password for the Java EE 6 SDK. The password file needs to be in the following format: `AS_ADMIN_PASSWORD=<admin-password>` Replace <admin-password> with the admin password of the application server. For `anonymous` user the password should be blank: `AS_ADMIN_PASSWORD=""` | `C:\glassfish3\glassfish\samples\ bp-project\passwordfile`
   `javaee.adminserver.port` | The port number for admin server. | `4848`
   `proxy.host` | The host name of your HTTP proxy server, if the system running Java EE 6 SDK is behind a firewall. Leave blank otherwise. | `myproxy.mydomain`
   `proxy.port` | The port number of your HTTP proxy server, if the server running Java EE 6 SDK is behind a firewall. Leave blank otherwise. | `9090`

   If you are not running the samples under Mac OS X or Windows, you will need to define the property 'default.browser' in the build.properties file.
4. Configure the built-in Java DB database.

   See Using Java DB with Sample applications for information on configuring the built-in Java DB database and corresponding JDBC resources.

### Building and Running a Sample Application

After performing the one-time setup tasks, you can build and run a sample application as follows:

1. Add the JDK 1.6.0_16 home and bin directories to your PATH environment variable. For example:

   `set PATH=C:\Program Files\Java\jdk1.6.0_16;%PATH%
   set PATH=C:\Program Files\Java\jdk1.6.0_16\bin;%PATH%`

2. Add the Ant 1.7.1 home and bin directories to your PATH environment variable. For example:

   `set PATH=C:\glassfish3\ant;%PATH%
   set PATH=C:\glassfish3\ant\bin;%PATH%`

3. Navigate to the `<javee.home>\bin` directory and then use the `asadmin` utility to start the application server and the Java DB database:

   `asadmin start-domain
   asaadmin start-database`

4. Follow the instructions for the specific sample to build and run it. Note that many of the samples use the following common Ant build targets:

   - all: compiles, packages the archive, deploys the application and run the sample
   - compile: compiles the sample application
   - package: packages the archive
   - default: compiles, packages the archive
   - run: runs the sample application
   - clean: undeploys the application, removes the generated directories like build and dist

### Sample Applications as NetBeans 6.8 Projects

You can open the sample applications as projects in the NetBeans 6.8 IDE. To do so, follow these steps after downloading and installing NetBeans 6.8 from the NetBeans Download page:

1. Set JDK 1.6.0_16 as the default Java platform by changing the `netbeans_jdkhome` property in the `<netbeans.home>\etc\netbeans.conf` file.
2. Configure the browser that the NetBeans IDE will use by selecting Tools->Options->General->WebBrowser.
3. Configure the GlassFish v3 server to use JDK 1.6.0_16 by selecting Tools->Servers and then clicking the Java tab for GlassFish v3 Domain.
4. Install the GlassFish v3 Enabler plugin from the Tools->Plugin window's Available Plugins tab. After installation, restart NetBeans.
5. Start the GlassFish server:

   1. Choose Windows->Services.
   2. Expand the Servers group.
   3. Right-click the GlassFish v3 domain and choose Start from the context menu.
6. Open one of the sample applications:

   1. Choose File->Open Project.
   2. Navigate to the `<javaee.home>\glassfish\samples\javaee6` directory and then to the appropriate sample project.
   3. Select the sample project.
   4. After NetBeans scans the project, select "Open Required Projects" if projects appear in the box below the option, and then click Open Project.
7. Check the sample's docs/index.html file for any special prerequisites or build instructions.
8. Right-click the sample project and execute one of the Ant targets; for example, `Run`.

Note: It is possible that the sample may not work correctly because of NetBeans caching. In that case, perform the following steps:

1. Close NetBeans IDE and remove the .netbeans directory from your home directory just to make sure nothing is cached. You may want to rename instead of deleting.
2. Start NetBeans IDE and GlassFish Server.
3. Open the specific sample project. Select the Open Required Projects option to avoid a File Not Found exception.
4. Run the create-file-user command using ant, if required.
5. Right-click the main sample project and select Run.

Copyright © 1997-2011 Oracle and/or its affiliates. All rights reserved.