GlassFish Developer Instruction

For complete build instructions, please see: FullBuildInstructions.

First, make sure your maven can find artifacts from the java.net maven2 repository.
This is done by making sure that your ~/.m2/settings.xml has a proper entry like this:

<settings>
  <!-- only if you are behind the proxy -->
  <proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
    </proxy>
  </proxies>
</settings>

If you're building in Oracle Network, set the proxy host and port as:

<host>www-proxy.us.oracle.com</host>
    <port>80</port>

Next, check out the part of the glassfish that you are interested in working on. For example,
if you are working on appserv-webtier, you'd do the following.

svn checkout https://svn.java.net/svn/glassfish-svn/trunk/main/appserver/web/appserv-webtier

You can then generate project files for your IDE by running the command like below. Due to the directory layout, this does not work for some of the modules. NetBeans and Intellij don't need such additional step as it can understand Maven natively by using a plugin.

mvn -DdownloadSources=true eclipse:eclipse       // for Eclipse

After you make your changes, you can build your module by running the following command.

mvn install

Once you are satisfied with your change, use svn to commit the changes.

Edit/Build/Debug Cycle

You'll be spending most of time going through edit/build/debug cycle, so making this step efficient is important for your productivity.

After you make changes, you can launch Glassfish with your local changes by running the following command:

mvn gf:run

This starts Glassfish with your module's target/classes and all the other pre-built binaries. The first time around it will take some time to download all those additional binaries, but from then on this should run fairly quickly.

To launch this Glassfish under the debugger, do as follows. You'll be running this often, so it's usually a good idea to make this a little shell script or an alias:

UNIX:
export MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5050

Windows:
setlocal
set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5050
mvn gf:run
endlocal

The same technique is also used if you need to tweak the VM launch parameter. See the plugin documentation for more about gf:run goal and how to customize its behavior.

Once Maven starts under debugger, connect your IDE remotely to the port, and you can debug it all you like. Also, be sure to learn about hot swapping, so that you can make simple changes from your IDE without restarting Glassfish.

Further Reading

Read more about how GFv3 build/development works to get a better understanding why this works. Also, see this jenblog entry for more build tips.

Other Productivity Tips

  • For building your module, Maven occasionally needs to hit the remote repository to check if any of your dependencies are updated. You can avoid this by running mvn with the -o option. This often reduces the build time.
  • Contrarily, if you want to force Maven to check updates to all your dependencies, run mvn with -U -up. This is often necessary when a change in your code depends on another change another developer made in another module.
  • Sun employees can use the internal maven repository mirrors for faster repository access.

TODO

  • Automate deployment via Hudson.

Hi can I import the glassfish projects into eclipse, I always get errors concerning the classpath.

Posted by veit_ullmann at Nov 04, 2011 10:05