Thursday, September 22, 2005

Creating a WAR file

  • Create a directory to place files in.
  • Inside this directory, create WEB-INF.
  • Create the directories tags, classes, and lib inside WEB-INF.
    classes will be the root of your Java code.
    lib contains the libraries you need (jar)
    tags contains tag files and JSP fragments (.jspf)
  • create web.xml inside WEB-INF
  • The format goes like this (remove spaces after <>):
<!--
Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
-->

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
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/web-app_2_4.xsd">
<display-name>MyAppsName</display-name>
<distributable/>

<!-- this sets up a resource for your application
to access the datasource with the JNDI name
mydatasource/myDB that you set up in the appserver -->
<resource-ref>
<description>JNDI Datasource</description>
<res-ref-name>mydatasources/myDB</res-ref-name>
<res-type>javax.sql.ConnectionPoolDataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

<!-- Loads a custom tag library-- can be accessed with the prefix mytaglib -->
<jsp-config>
<taglib>
<taglib-uri>mytaglib</taglib-uri>
<taglib-location>/WEB-INF/lib/mytaglib.jar</taglib-location>
</taglib>
</jsp-config>

</web-app>

  • In addition, if you are using appserver8 you will need to create sun-web.xml, which rehashes some of the info in web.xml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//
DTD Application Server 8.1 Servlet 2.4//EN"
"http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd">
<sun-web-app>
<context-root>/MyAppsPath</context-root>
<resource-ref>
<res-ref-name>mydatasources/myDB</res-ref-name>
<jndi-name>mydatasources/myDB</jndi-name>
</resource-ref>
</sun-web-app>


  • Now create your web application in this directory.
  • cd into the directory you wish to turn into a war file
  • $ jar cvf WARFILENAME.war *
  • If you are using Sun appserver8, you can use $IAS_ROOT/bin/verifier path/to/war/file to verify your war file. In your current directory, the verifier will create a file called YOURWARFILE.war.txt which contains details of errors and warnings. Note that like a compiler, once the verifier hits some number of errors, it will stop outputting them. So you will need to correct the errors, then try running the verifier again.
  • Now deploy your application and cross your fingers :) This can be done manually in Tomcat and AppServer8 or you can copy the war file into $IAS_ROOT/domains/domain1/autodeploy - if successful, you'll see a file in this directory YOURWARFILE.war_deployed, if it fails you'll see a file that ends with deploy_failed. Look in $IAS_ROOT/domains/domain1/logs/server.log for details. You can force the AS to try to deploy again by removing *deploy_failed and "touch"ing your war file.

No comments:

Labels

Blog Archive

Contributors