about

J2EE WAR boilerplate configuration for JDBC, JSP, JSTL, Servlets - 09 Feb 2012

search

I found out the long way that building a properly working .war is all about the correct archive structure. For this particular situation I was deploying to a Tomcat 6 instance. This walk-through assumes you already have a working web server/Servlet container with some way to deploy your .war.

To create a project that will deploy with support for JavaServer Pages, JavaServer Pages Standard Tag Library, Servlets, and MySQL (via their custom JDBC driver), you will need something like the following structure in place:

j2ee_war/
    | -> build.xml
    | -> META-INF/
    | | -> context.xml
    | -> src/
    | | -> config/
    | | | -> DbConn.java
    | | -> database/
    | | | -> UserManager.java
    | | -> servlets/
    | | | -> MyInfo.java
    | -> war-no-include/
    | | -> jsp-api.jar
    | | -> servlet-api.jar
    | -> web/
    | | -> favicon.ico
    | | -> index.html
    | | -> login.jsp
    | -> WEB-INF/
    | | -> web.xml
    | | -> lib/
    | | | -> jstl-1.2.jar
    | | | -> mysql-connector-java-5.1.18-bin.jar

j2ee_war.zip

NOTE

1) The libraries in the war-no-include directory need to be in the build class path when compiling beans and servlets, but should not be in the deployed war as the servlet container provides its own version of these libraries. This is taken care of in the included ant build.xml file.

2) The jstl-1.2.jar library (for JSTL support) contains both the API and implementation. See BalusC's response to javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/ConditionalTagSupport.


260 words. Post tags: J2EE, JDBC, JSP, and JSTL.

Post content is written by Jason Zerbe and licensed CC BY-NC 3.0.