Deploying Web Applications to Tomcat

Deploying Web Applications to Tomcat

To complete your deployment, copy the compiled tag library and the taglib.tld into the TOMCAT_ROOT/onjava/WEB-INF/lib directory.

To test you new tag library, you need to modify the welcome.jsp page, replacing the Welcome message with a reference to the <onjava:hello /> tag. You need to also add a taglib directive referencing the taglib.tld to the welcome.jsp file. The modified JSP is in Listing 7.


Listing 7 Modified welcome.jsp

<%@ taglib uri="/onjava" prefix="onjava" %>
<html>
<head>
 <title>Onjava Demo</title>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

 <table width="500" border="0" cellspacing="0" cellpadding="0">
  <tr>
   <td> </td>
  </tr>
  <tr>
  <td>
   <img src="/onjava/images/monitor2.gif"></td>
  <td>
   <b><onjava:hello /> : <%= request.getAttribute("USER") %></b>
  </td>
  </tr>
  <tr>
   <td> </td>
  </tr>
 </table>
</body>
</html>

Now open the login.jsp page as described previously and run through the demo again. This time instead of Welcome: Bob, you should see the message Hello: Bob.

Creating and Deploying a WAR File

When your web application is ready for deployment, you need to package it for distribution. As we discussed previously in Java Web Applications, web applications are packaged in WAR files. The steps required to "WAR-up" your /onjava web application and deploy it are as follows:

  1. Change to the root directory of your web application. In this case the root directory would be TOMCAT_HOME/webapps/onjava/.

  2. Archive the web application:

    jar cvf onjava.war .
  3. Copy the resulting WAR file, onjava.war, to the TOMCAT_HOME/webapps directory.

    If you're deploying this WAR file to the Tomcat installation that you were developing in, then you will need to back up your development directory and remove it from the TOMCAT_HOME/webapps directory.

  4. Add a new Context entry to the /TOMCAT_HOME/conf/server.xml file, referencing the onjava web application.

  5. Restart Tomcat.

That's it. Your application should now be deployed and running. If it isn't, check your entry in the TOMCAT_HOME/conf/server.xml file to ensure that you have set the appropriate values.

Now that you know how to create and deploy a web applications, we'll examine the relationship of the web application and its ServletContext in a future article.

James Goodwill is the co-Founder of Virtuas Solutions, LLC, a Colorado-based software consultancy.


Read more Using Tomcat columns.

Return to ONJava.com.

Prev  [1] [2] [3] [4] [5] 

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > Java Servlets > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction