The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Migrating Tomcat's Hello World to GlassFish

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

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

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 Migrate To GlassFish project.

Comments
Comments are listed in date ascending order (oldest first)

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

Hi sekhar ,good article. But I run my jersey app in tomcat and want to use Spring Security 2.0.0 to do the authentication and the authorization jobs :) Please give me some ideas how to implement it! Thanks. estetik

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 Tom, I will be posting a schedule fairly soon and would welcome feedback. Thanks Sekhar

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 ankaranakliyat133 : Thanks for the feedback. I have forwarded your request to my collegues and designers of Jersey - Marc Hadley and Paul Sandoz.

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?