Last Modified: Wed, 11 Sep 2013 19:35:35 +0000 ; Created: Wed, 11 Sep 2013 19:33:06 +0000
I used:
Creating the project
Create the Eclipse project
Get it to actually runNext we must modify some variables in Eclipse in order to get it to actually build and run the project.
Maven servlet dependenciesA helpful list of how to resolve servlet-api names for newer versions (it is very inconsistent on all the Maven repos) can be found at http://maven.apache.org/guides/mini/guide-coping-with-sun-jars.html, but beware that newer releases of the servlet apis don't seem to follow these recommendations anymore. Sample pom.xml<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>TLD.EXAMPLE.GROUP</groupId> <artifactId>YOUR-ARTIFICAT-ID</artifactId> <packaging>war</packaging> <version>-SNAPSHOT</version> <name>YOUR-PROJECT-NAME Maven Webapp</name> <url>http://www.rodneybeede.com</url> <inceptionYear>2013</inceptionYear> <licenses> <license> <name></name> <url></url> <distribution>repo</distribution> <comments></comments> </license> </licenses> <organization> <name>SOME ORG</name> <url>http://www.example.com/</url> </organization> <developers> <developer> <id>rbeede</id> <name>Rodney Beede</name> <email>nospam_see_project_website@localhost</email> <url>http://www.rodneybeede.com/</url> <organization>TODO</organization> <roles> <role>architect</role> <role>developer</role> <role>tester</role> </roles> </developer> </developers> <contributors> <contributor> <name></name> <email>nospam_see_project_website@localhost</email> <organization></organization> <roles> <role>tester</role> </roles> </contributor> </contributors> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>apache-log4j-extras</artifactId> <version>1.1</version> </dependency> <!-- Maven Central and other repos don't have consisent locations for versions of the J2EE APIs This guide was helpful for older versions, but it doesn't seem to be followed anymore in repos: http://maven.apache.org/guides/mini/guide-coping-with-sun-jars.html You can also search http://jcp.org/en/jsr/all to get the middle point (x.'#'.z) latest JSR spec version --> <!-- http://www.java.net/forum/topic/glassfish/glassfish/javaxservlet-api-version --> <!-- http://java.net/projects/servlet-spec --> <!-- Found in Maven central repository --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <!-- http://jsp.java.net/downLoad.html --> <!-- Found in Maven central repository --> <dependency> <groupId>javax.servlet.jsp </groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> <scope>provided</scope> </dependency> <!-- Find the latest version with groupId and artifactId per http://jstl.java.net/download.html --> <!-- Found in Maven central repository --> <dependency> <groupId>org.glassfish.web</groupId> <artifactId>javax.servlet.jsp.jstl</artifactId> <version>1.2.2</version> </dependency> </dependencies> <build> <finalName>YOUR_WEBAPP_CONTEXT_PATH_NAME</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <configuration> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> <wtpversion>2.0</wtpversion> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> </project> Sample web.xml<?xml version="1.0" encoding="UTF-8"?> <!-- Java Servlet Specification version 3.1 final document has an old example of only version 2.5. This website (http://antoniogoncalves.org/2013/06/04/java-ee-7-deployment-descriptors/) provided the updated example of the web-app tag --> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <display-name>YOUR_WEBAPP_NAME</display-name> <context-param> <description>Location where the web application configuration can be found. We keep the configuration options separate from the web.xml because it makes redeployment easier to avoid having to update web.xml for each environment.</description> <param-name>Pathname to configuration file</param-name> <param-value>/etc/WebAppConfig.xml</param-value> </context-param> <listener> <description>Responsible for initializing the web application at startup</description> <listener-class>TLD.DOMAIN.WEBAPP.servlets.InitializationListener</listener-class> </listener> <servlet> <servlet-name>SomeServlet</servlet-name> <servlet-class>TLD.DOMAIN.WEBAPP.servlets.SomeServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>SomeServlet</servlet-name> <url-pattern>/servlets/SomeServlet</url-pattern> </servlet-mapping> <security-constraint> <web-resource-collection> <web-resource-name>HTTP Method Security</web-resource-name> <description>Restricts HTTP methods to only allowed methods for best security practice</description> <url-pattern>/</url-pattern> <http-method-omission>GET</http-method-omission> <http-method-omission>POST</http-method-omission> </web-resource-collection> </security-constraint> </web-app> |
|