Deploying the Application


Both the web and EJB sides of the application are ready. It is possible to deploy the WAR and EJB JAR files created directly to JBoss, but that would require a few more additional configuration steps to link the two parts of the application together. Instead, we'll assemble the application into an EAR file for deployment. It's not only better design, it's also easier.

How do I do that?

When you build the application, a todo.ear file is created in the build/jars directory. The EAR file combines the todo.jar and todo.war archives into one larger package. The structure is simple:

     [todo]$ jar tf build/jars/todo.ear     META-INF/     META-INF/application.xml     todo.jar     todo.war 

All that is required is a J2EE application.xml deployment descriptor. XDoclet doesn't generate it, but it is easy enough to produce by hand:

     <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>todo</context-root>             </web>         </module>     </application> 


Note: In the absence of explicit configuration, JBoss uses the base name of the WAR file as the context root.

The deployment descriptor lists the archives, and in the case of the WAR file it adds the context root of the application telling JBoss what URL space the application serves. The context root is set to todo, which is what JBoss would have used had we deployed the todo.war file separately.

To deploy the application, copy the EAR file to the JBoss deploy directory. To get the Ant build file to do this for you, you should set the jboss.dir property to the location of your JBoss install directory:

     <property name="jboss.dir" location="/tmp/jboss-4.0.2" /> 

Running the deploy target copies the EAR file out to the deploy directory of the default configuration:

     [todo]$ ant deploy     Buildfile: build.xml     deploy:          [copy] Copying 1 file to /tmp/jboss-4.0.2/server/default/deploy     BUILD SUCCESSFUL     Total time: 2 seconds 

When you do this, you will see the results of your deployment in the console window:

     00:58:37,011 INFO  [EARDeployer] Init J2EE application: file:/private/tmp/     jboss-4.0.2/server/default/deploy/todo.ear     00:58:37,857 INFO  [EjbModule] Deploying Task     00:58:37,881 INFO  [EjbModule] Deploying Comment     00:58:37,917 INFO  [EjbModule] Deploying TaskMaster     00:58:38,482 INFO  [EJBDeployer] Deployed: file:/private/tmp/jboss-4.0.2/     server/default/tmp/deploy/tmp15658todo.ear-contents/todo.jar     00:58:38,543 INFO  [TomcatDeployer] deploy, ctxPath=/todo, warUrl=file:/     private/tmp/jboss-4.0.2/server/default/tmp/deploy/tmp15658todo.ear-contents/     todo.war/     00:58:39,664 WARN  [Digester] [NavigationRuleRule]{faces-config/navigation-rule} Merge(*)     00:58:40,477 INFO  [EARDeployer] Started J2EE application: file:/private/     tmp/jboss-4.0.2/server/default/deploy/todo.ear 


Note: Remember that deployment in JBoss is just a simple copy.

You can see JBoss generates a log message for each bean that is deployed. The Deploying Task, Deploying Comment, and Deploying TaskMaster messages confirm that those beans were successfully deployed. The Tomcat deployer logs a message telling us that the web application has been deployed and is indeed serving the /todo context root. Finally, the Started J2EE application message lets us know that the application as a whole has completed its deployment.

All that is left is to try and access the application. Since the application is serving the /todo context root, the full application can be accessed at http://localhost:8080/todo/.

When prompted to log in, enter a name and password from the users.properties file. Once you do that, the Figure 3-1 shows the application in action.

Developer's Notebook 3-1. The ToDo application


The application supports task comments and a few other simple operations. But the most important thing is that the application is really up and running in JBoss.


Note: J2EE with no configuration? It hardly seems possible.

What just happened?

The ToDo application has been deployed and all the J2EE services are functioning. Transactions and security are wired up and JBoss has even created the database tables in which it needs to store entity bean data. That last feature is pretty amazing, considering we haven't configured anything related to the database yet. In fact, it is interesting enough that we should spend a little more time looking at how JBoss is storing the EJB data.



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