Attachment 'WebappBuilder.xml'

Download

   1 <?xml version = '1.0' encoding = 'ISO-8859-1'?>
   2 <!-- a build file for creating new, empty webapps
   3      to use, simply run "ant -Dappname=yourappname" 
   4 -->
   5 
   6 <project name="WebappBuilder" default="create" basedir=".">
   7 
   8  <target name="create">
   9    <mkdir dir="${appname}/WEB-INF/classes"/>
  10    <mkdir dir="${appname}/WEB-INF/lib"/>
  11    <concat destfile="${appname}/WEB-INF/web.xml"><![CDATA[<?xml version="1.0" encoding="ISO-8859-1"?>
  12 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  13     "http://java.sun.com/dtd/web-app_2_3.dtd">
  14 <web-app>
  15 <!-- this descriptor file MUST be well-formed XML,
  16      and must validate against the DTD mentioned in the DOCTYPE.
  17      Ordering of elements is extremely important!
  18 -->
  19 
  20     <display-name>${appname}</display-name>
  21     <description></description>
  22     
  23 <!-- example context-param 
  24      use this to set any parameters for this webapp.
  25      retrieve with getServletContext().getInitParameter("param-name")
  26      (or in JSP, simply context.getInitParameter("param-name") )
  27      
  28   	<context-param>
  29   		<param-name>NAME</param-name>
  30   		<param-value>VALUE</param-value>
  31   	</context-param>
  32 -->
  33 
  34 <!-- example servlet definition 
  35      <servlet-class> should be the class name of your servlet
  36      either inside a jar in WEB-INF/lib or under a directory 
  37      structure matching the package name under WEB-INF/classes
  38      
  39   <servlet>
  40     <servlet-name>mypackage.MyServlet</servlet-name>
  41     <servlet-class>NameofServletClass</servlet-class>
  42   </servlet>
  43 -->    
  44 
  45 <!-- example servlet mapping 
  46      <servlet-name> must match a defined servlet above.
  47      <url-pattern> should be the request that triggers
  48      the servlet, relative to the webapp itself.
  49      A request for http://localhost/${appname}/TestServlet
  50      would be matched by <url-pattern>/TestServlet</url-pattern>
  51      
  52   <servlet-mapping>
  53     <servlet-name>MyServlet</servlet-name>
  54     <url-pattern>/MyServlet</url-pattern>
  55   </servlet-mapping>
  56 -->
  57 
  58 <!-- example welcome-file definition
  59      used to set a default document for your webapp's
  60      directories
  61 -->
  62 
  63    <welcome-file-list>
  64      <welcome-file>index.jsp</welcome-file>
  65      <welcome-file>index.html</welcome-file>
  66      <welcome-file>index.htm</welcome-file>
  67    </welcome-file-list>
  68 
  69 <!-- example error-page definition
  70      used to either map HTTP-related errors
  71      or Java Exceptions to an error document
  72      
  73      <error-page>
  74        <exception-type>NullPointerException</exception-type>
  75        <location>/missing-data.jsp</location>
  76      </error-page>
  77 -->
  78 
  79      <error-page>
  80        <error-code>404</error-code>
  81        <location>/notfound.jsp</location>
  82      </error-page>
  83 
  84 <!-- example JDBC / JNDI resource 
  85      this should match a predefined data source
  86      in the server's main configuration file.
  87      
  88   <resource-ref>
  89       <description>DB Connection</description>
  90       <res-ref-name>jdbc/MyDataSource</res-ref-name>
  91       <res-type>javax.sql.DataSource</res-type>
  92       <res-auth>Container</res-auth>
  93   </resource-ref>
  94 -->
  95 </web-app>
  96 ]]></concat>
  97   <concat destfile="${appname}/notfound.jsp"><![CDATA[<%@page language="java"%>
  98 <html>
  99  <head>
 100   <title>404 Not Found</title>
 101  </head>
 102  <body>
 103   <h2>404 Not Found</h2>
 104   <p>The page '<strong><%= request.getRequestURI() %></strong>'
 105    was not found on this server.</p>
 106   <p>&nbsp;</p>
 107   <p>&nbsp;</p>
 108   <p>&nbsp;</p>
 109   <p>&nbsp;</p>
 110   <p>&nbsp;</p>
 111   <p>&nbsp;</p>
 112   <p>&nbsp;</p>
 113   <p>&nbsp;</p>
 114  </body>
 115 </html>
 116 ]]></concat>
 117   <concat destfile="${appname}/index.html"><![CDATA[<html>
 118  <head>
 119   <title>${appname} - A new webapp</title>
 120  </head>
 121  <body>
 122   <h2>${appname} - A new webapp</h2>
 123   <p>Welcome to your new web application!</p>
 124   <h3>To Do:</h3>
 125   <ul>
 126    <li>Add any libraries (jars) to WEB-INF/lib</li>
 127    <li>Add any servlets or helper classes to WEB-INF/classes</li>
 128    <li>Make any configuration changes to WEB-INF/web.xml</li>
 129    <li>Develop your new web application!</li>
 130   </ul>
 131   <p>&nbsp;</p>
 132   <p>&nbsp;</p>
 133   <p>&nbsp;</p>
 134   <p>&nbsp;</p>
 135   <p>&nbsp;</p>
 136   <p>&nbsp;</p>
 137   <p>&nbsp;</p>
 138  </body>
 139 </html>
 140 ]]></concat>
 141 
 142 <concat destfile="${appname}/WEB-INF/classes/ServletTemplate.java"><![CDATA[import java.io.*;
 143 import javax.servlet.*;
 144 import javax.servlet.http.*;
 145 
 146 public class ServletTemplate extends HttpServlet {
 147   
 148   public void doGet(HttpServletRequest request, HttpServletResponse response)
 149    throws ServletException, IOException {
 150     response.setContentType("text/plain");
 151     PrintWriter out = response.getWriter();
 152     out.println("TO DO:");
 153     out.println("======");
 154     out.println("Make this servlet do something more useful!");
 155     }
 156   
 157   public void doPost(HttpServletRequest request, HttpServletResponse response)
 158    throws ServletException, IOException { doGet(request, response); }
 159 
 160   }
 161 ]]></concat>
 162  </target>
 163  
 164  <target name="war" depends="create">
 165    <jar destfile="${appname}.war" basedir="${appname}"/>     
 166    <delete dir="${appname}"/>
 167  </target>
 168 
 169 </project>

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-03-22 06:01:33, 5.0 KB) [[attachment:WebappBuilder.xml]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.