Setting a Root Web Application


When you access JBoss for the first time, JBoss provides you with the default root application, shown in Figure 9-1.

Developer's Notebook 9-1. Default root application


In production, you'll want your own application to serve the root context.

How do I do that?

Controlling the context of a web application is different for WAR files deployed inside of an EAR file and for WAR files deployed as standalone files.


Note: If you didn't change the HTTP port to 80, make sure you use http://localhost:8080/.

EAR files contain a standard J2EE mechanim for controlling the context of the web application. The context-root element of a web module in application.xml controls the root web application. Setting the root context to / will place the ToDo application at the root context. In the ToDo application the change will look like this:

     <application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee              http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">         <display-name>JBoss Notebook ToDo Application</display-name>         <description>JBoss Notebook ToDo Application</description>         <module>             <ejb>todo.jar</ejb>         </module>         <module>             <web>                 <web-uri>todo.war</web-uri>                 <context-root>/</context-root>             </web>         </module>     </application> 

If you make this change and redeploy the application, accessing http://localhost/ will bring you directly to the ToDo application.

For a standalone WAR file, the context-root element should be added to jboss-web.xml. We'll go back to the quote machine web application from Chapter 2. Create a jboss-web.xml file in quote/src/metadata that looks like this:


Note: JBoss won't complain if you have multiple applications wanting to serve the root context, but only the most recently deployed one will be active.
     <!DOCTYPE jboss-web PUBLIC               "-//JBoss//DTD Web Application 2.4//EN"               "http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">     <jboss-web>             <context-root>/</context-root>     </jboss-web>. 

Now that you've done that, you can redeploy your application. When you go to http://localhost/, you'll see the quote application running.

What just happened?

You saw how to set an application to serve the root context in JBoss. With EAR files, declaring the context root can be done in an application-server-independent way. However, with a standalone WAR file, you had to use the jboss-web.xmlfile to declare the context.



JBoss. A Developer's Notebook
JBoss: A Developers Notebook
ISBN: 0596100078
EAN: 2147483647
Year: 2003
Pages: 106

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net