站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Netbeans 专题Developing and Building Project GlassFish with NetBeans

Developing and Building Project GlassFish with NetBeans

摘要: Project GlassFish, Sun's open source application server development effort on Java.net, has already been set up to work with NetBeans. Each of the 30 modules that comprise project GlassFish have been set up as a NetBeans project. This article will show you how to set up your environment in order to edit, build and run project GlassFish using NetBeans. In addition, I show you how to modify the project settings and set up new modules if the need arises. For full details on the steps referenced in this document, please see complete set of instructions on how to build GlassFish.

Setting Up Your Environment

NetBeans

Download and install NetBeans 4.1

Maven

Download and install Maven. Verify your installation by running "maven -v" at the command prompt.

Getting the GlassFish Source

Create Your Workspace Home

  1. Create a "workspace" directory.
  2. cd workspace

Get the Source

  1. Log into CVS:
    cvs -d :pserver:<java.net userid>@cvs.dev.java.net:/cvs login
  2. Checkout the glassfish module:
    cvs -d :pserver:<java.net userid>@cvs.dev.java.net:/cvs checkout glassfish/bootstrap

Set the Project Properties

  1. CD to glassfish/bootstrap
  2. Set the following in project.properties:
    • glassfish.os.name=[WINNT, Linux, SunOS, SunOS_X86]
    • glassfish.cvs.username=<your java.net userid>
    • glassfish.root=D:/workspace
    • Note, for developers on Windows, if your GlassFish source is on a different drive then your NetBeans installation, you need to prefix glassfish.root with the drive letter containing the GlassFish source:

Get, Configure and Test the GlassFish Image

In this step we will download and install complete working version of GlassFish. The GlassFish image will be downloaded to your Maven repository, and from there, extracted to your glassfish.home as configured in your glassfish/project.properties file. When building modules that have dependencies on other modules, the incremental builds will use the libraries from glassfish.home to resolve those classpath dependencies.
  1. While still in the boostrap directory, run "maven bootstrap". Note, the GlassFish image is over 60 MB, so this step will take a couple of minutes.



  2. Run"maven configure-runtime"



  3. Change directories to ..\..\publish\glassfish\bin and run "asadmin list-domains".

Checkout, Open and Modify a GlassFish Module Project in NetBeans

For this exercise, we'll make a modification to the admin-cli project.

Get the admin-cli Sources

  1. cd to workspace/glassfish/bootstrap
  2. Checkout the admin-cli module:

    maven checkout -Dmodules=admin-cli,appserv-docs

  3. cd ../appserv-docs
  4. Run "maven build"
    Note, steps 3 & 4 are required because the admin-cli module is dependant on appserv-docs.

Open the Admin Cli Project in NetBeans

  1. Start NetBeans and Choose File > Open Project (Ctrl+Shift+0).
  2. Browse to the /workspace/glassfish/admin-cli. Notice the badge NetBeans places on the folder icon, which indicates NetBeans recognizes it as a project.

Modify the GlassFish Source

  1. Expand the commands/src/java source root and the com.sun.enterprise.cli.commands package.
  2. With focus still in the Projets tab, type "S1AS" and hit Enter. This opens a Quick Search which jumps to the file and opens it.



  3. Press Ctrl+7 and type "val". This will jump you to the validate options method.
  4. Add the top of the method, type "sout" and press space. This will expand to system.out.println("");. Type "Welcome to Glassfish" between the quotes.

    System.out.println("Welcome to Project GlassFish!");

Build and Test the Change

  1. Press F11 to lauch the module's build script. The build script update the jar in your glassfish.home.
  2. Change directories to /workspace/publish/glassfish/bin and run "asadmin list-domains".

About the GlassFish NetBeans Projects

There are about 30 modules that make up project GlassFish, each of which has been set up for you as a NetBeans project of type Free-Form Project. Since the Free-Form Project type is designed for projects with an existing Ant script, NetBeans creates an ancillary file called project.xml to:

  • Map existing Ant targets to IDE specific commands
  • Inform NetBeans of the project's source directory(ies)
  • Inform the NetBeans editor of the project's classpath.

You'll find the project.xml file in a subdirectory called nbproject.

Mapping Ant Targets to IDE Commands

If you view any of the GlassFish module project's Build and Run properties, you'll see that both the Build and Clean project menu items have been mapped for you.

To learn more about this project type, see Advanced Free-Form Project Configuration.

Configuring the Project's Source Directory(ies)

NetBeans' logical Projects view shows the GlassFish module's various source directories. In the example below, the Admin CLI project has 3 configured source directories.

These directories are configured in the project's Java Sources properties.

Configuring the Editor's Classpath

The NetBeans editor does not pull the classpath information from the Ant build script. Although the module will build, it will not look pretty in the editor. For example, here's the S1ASCommand.java before the classpath was configured.

The GlassFish build scripts use the libraries from the extracted GlassFish image for its classpath. The location for these libraries is configured in the glassfish module's project.properties file (we checked out the glassfish module above when we got the source).

Like the build target and source root configuration, this can also be done via the project's property editor. However, using the property editor would set absolute paths to required libraries, therefore, we've manually edited the project.xml file so we could reference the glassfish/project.properties when configuring the editor's classpath.

First, we import the glassfish/project.properties into the project.xml file.

Then you reference glassfish/project.properties that map to jar files. Note that each source root has its own classpath. So in the example below, the sources in the cli-api/src/java have no other dependencies. However, the sources in commands/src/java depend on classes in admin-cli.jar, appserv-admin.jar and appserv-rt.jar.

If, while working in any of the GlassFish modules, you have unresolved compiler errors in the NetBeans editor, its a matter of simply adding the missing jar files to the classpath.

Note, the properties to resolve nicely when viewed from the NetBeans Project Property editor.

To learn more about this project type, see Advanced Free-Form Project Configuration.

NetBeans Support for Maven

NetBeans does have a plug-in for Maven. However, the GlassFish Project has not yet set up the project dependencies as expected by Maven. In this stage, Maven is really used as a wrapper around the GlassFish project's existing Ant based build infrastructure. In a future stage, the GlassFish team intends to provide more pure support of Maven.

↑返回目录
前一篇: Developer Guide to BPEL Designer
后一篇: Developing Applications for TiVo in NetBeans