Maven archetype for easy servlet use

Is there a Maven 2 archetype for a simple Servlet (2.5) web application?

+45
java maven-2 maven-archetype servlets
May 6 '10 at 3:01 a.m.
source share
6 answers

There is an archetype for webapp there :

mvn archetype:generate -DgroupId=com.acme \ -DartifactId=my-webapp \ -Dversion=1.0-SNAPSHOT \ -DarchetypeArtifactId=maven-archetype-webapp \ -DinteractiveMode=false 

This will create the following structure:

 $ tree my-webapp /
 my-webapp /
 β”œβ”€β”€ pom.xml
 └── src
     └── main
         β”œβ”€β”€ resources
         └── webapp
             β”œβ”€β”€ index.jsp
             └── WEB-INF
                 └── web.xml

Where web.xml is Servlet 2.3 web.xml:

 $ cat my-webapp/src/main/webapp/WEB-INF/web.xml <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> </web-app> 

For a Servlet 2.5 web application, replace it with the following:

 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Archetype Created Web Application</display-name> </web-app> 

I do not know for NetBeans, but Eclipse (more precisely M2Eclipse) relies on web.xml to set up the project facets (so you need to change web.xml before importing, Eclipse will not update the web face if you change web.xml after the facts).

+66
May 6 '10 at 17:53
source share

I created a simple archetype for creating webapps based on Servlet 3: http://maciejwalkowiak.imtqy.com/servlet3-maven-archetype/

Just clone it, install and generate a project that uses Servlet 3, no XML, Tomcat7 ready (plugin included)

+13
May 22 '13 at 15:41
source share

you can start with

 mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp 

List of other archetypes, please refer to the list of archetypes

+3
May 06 '10 at 16:20
source share

Updated archetype number.

Note. By default, archetype 'maven-archetype-webapp' creates a Servlet 2.3 application. To upgrade to Servlet 2.5, kindly follow message # 1343356 from Pascal Thivent




Submit this link Maven's Exclusive List of Archetypes and follow this link for How to Use This Archetype .

Commonly used archetype numbers:

  • 610 -> org.apache.maven.archetypes: maven-archetype-webapp (Archetype containing a sample Maven Webapp project)
  • 600 -> org.apache.maven.archetypes: maven-archetype-j2ee-simple (An archetype that contains a simplified sample J2EE application.)

OR just use the convenient maven command below -

 $ mvn archetype:generate -DgroupId=com.sample -DartifactId=servlet-app -Dversion=0.1-SNAPSHOT -DarchetypeArtifactId=maven-archetype-webapp 
+1
Jul 01 2018-12-12T00:
source share
  • Create a maven project using the maven-archetype-webapp archetype

Command: mvn archetype: create -DgroupId = com.lei.webapp.quickstart -DartifactId = webapp-quick-start-DarchetypeArtifactId = maven-archetype-webapp

  • Add the following dependency to pom.xml:

    javax.servlet servlet api 2.5

+1
Feb 24 '16 at 15:47
source share

I authorize the IDE (my is Intellij IDEA) to create a basic webapp structure for me.

Switch to:

File -> New project -> create from archetype -> ... archetype-WebApp

This will give the basic structure of webapp.

0
Apr 26 '17 at 5:15
source share



All Articles