Earlier I introduced the Migrate to GlassFish project. Periodically, I will be taking examples to illustrate migrations to GlassFish. Here, I took the Tomcat example application and migrated it to GlassFish. Even though this is a simple example, it nonetheless illustrates a few of the deployment aspects of GlassFish.

First point to note is that no changes are necessary for the Tomcat sample application itself. Apache Tomcat version 6.0 implements the Servlet 2.5 and JavaServer Pages 2.1 specifications. GlassFish V2 implements which Java EE 5 which requires JSP 2.1 and Servlet 2.5. So you can can simply take the war file and deploy it as shown below:

  • Download and configure GlassFish V2
  • asadmin start-domain
  • asadmin deploy --user admin --passwordfile sample.war


  • I used the command line admin commands but you can use the admin console GUI.
  • The password file contains the admin password in the form AS_ADMIN_PASSWORD=password-value .

Note that no other GlassFish server specific deployment descriptors (e.g. sun-web.xml ). The context root for the web application is derived from the war file name (in this case "sample"). You can acccess the sample application at http://localhost:8080/sample . If you access the URL, you should see "Hello World" application with two links to "JSP Page" and "Servlet" .

When deployed as shown above, the JSP in the sample application are compiled at runtime the first time the "JSP Page" link is accessed. However, it is possible to precompile JSP at deployment time as follows:

  • asadmin undeploy --user admin --passwordfile passwordfile sample
    asadmin deploy --user admin --passwordfile passwordfile --precompilejsp sample.war

You will find the compiled JSP files can be found ingf-appserver-domain-dir/generated/jsp/j2ee-modules/sample . There are other ways to precompile JSP files. The above was just one way to do it.

Instead of war, you can deploy the sample application in an unpacked form. This is useful during development To do this:

  • unpack the sample.war into sample-dir
  • asadmin deploydir --user admin --passwordfile passwordfile sample-dir

I will be back with more examples.

If you are migrating applications to GlassFish, post your questions and feedback to Migrate To GlassFish forum and visit Migrate To GlassFish project.