Skip to main content

Migrating Tomcat's Hello World to GlassFish

Posted by sekhar on January 18, 2008 at 1:25 PM PST

Earlier I introduced the href="http://weblogs.java.net/blog/sekhar/archive/2008/01/introducing_mig.html">
Migrate to GlassFish project. Periodically, I will be taking
examples to illustrate migrations to GlassFish. Here, I took the href="http://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/">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 href="https://glassfish.dev.java.net/downloads/v2ur1-b09d.html">GlassFish
    V2

  • asadmin start-domain
  • asadmin deploy --user admin --passwordfile sample.war

Note:

  • 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 in
gf-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 href="https://migrate2glassfish.dev.java.net">Migrate To GlassFish project.

Comments

I tried this tools on windows platform: I always met following error: sun.iasmt.user.cmd.backendenablers.InputArgException: 204:Insufficient disk space. File: d:migrate2g lassfishsamplesample_tomcat_hello needs: 4852 bytes available: 0 bytes Could you give any idea for this?

Hi ankaranakliyat133 : Thanks for the feedback. I have forwarded your request to my collegues and designers of Jersey - Marc Hadley and Paul Sandoz.

Hi Sekar, Would be great if the migration tool you're talking about could also do something about Tomcat's my.war!/META-INF/context.xml to have resources generated somehow. Looking forward to next articles :) Cheers, Soren

Hi Tom, I will be posting a schedule fairly soon and would welcome feedback. Thanks Sekhar

Hi Soren, - Support for context.xml was added to GlassFish. See http://weblogs.java.net/blog/amyroh/archive/2007/05/context_webapp_1.html . My plan was to investigate the level of support (if any) that migration tool would need to provide for context.xml. Are you are aware of any resources in context.xml that are not handled by GlassFish but could be generated by migration tool ? Thanks for your feedback -Sekhar

Hi Sekar, -Can you post a schedule so we can watch and comment on which migration activities you are working on? Thank you, Tom