How to create a project with Maven template
Maven, comes with more than 40+ Maven templates to let developer to quick start a new Java project. See following steps to create a new Java project with Maven command “mvn archetype:generate“.
1. Maven – mvn archetype:generate
Navigate to folder that you want Maven to generate the project, e.g “E:\workspace\test“, and issue this command “mvn archetype:generate”. Maven will list out exiting 40+ Maven template projects for you to choose.
In this example, choose 18 to create a simple Java web application project template.
E:\workspace\test>mvn archetype:generate [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping ... Choose archetype: 1: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF) 2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC) 3: internal -> appfuse-basic-struts (AppFuse archetype for creating a web application with Hibernate, Spring and Struts 2) 4: internal -> appfuse-basic-tapestry (AppFuse archetype for creating a web application with Hibernate, Spring and Tapestry 4) 5: internal -> appfuse-core (AppFuse archetype for creating a jar application with Hibernate and Spring and XFire) 6: internal -> appfuse-modular-jsf (AppFuse archetype for creating a modular application with Hibernate, Spring and JSF) 7: internal -> appfuse-modular-spring (AppFuse archetype for creating a modular application with Hibernate, Spring and Spring MVC) 8: internal -> appfuse-modular-struts (AppFuse archetype for creating a modular application with Hibernate, Spring and Struts 2) 9: internal -> appfuse-modular-tapestry (AppFuse archetype for creating a modular application with Hibernate, Spring and Tapestry 4) 10: internal -> maven-archetype-j2ee-simple (A simple J2EE Java application) 11: internal -> maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade) 12: internal -> maven-archetype-mojo (A Maven Java plugin development project) 13: internal -> maven-archetype-portlet (A simple portlet application) 14: internal -> maven-archetype-profiles () 15: internal -> maven-archetype-quickstart () 16: internal -> maven-archetype-site-simple (A simple site generation project) 17: internal -> maven-archetype-site (A more complex site project) 18: internal -> maven-archetype-webapp (A simple Java web application) 19: internal -> jini-service-archetype (Archetype for Jini service project creation) 20: internal -> softeu-archetype-seam (JSF+Facelets+Seam Archetype) 21: internal -> softeu-archetype-seam-simple (JSF+Facelets+Seam (no persistence) Archetype) 22: internal -> softeu-archetype-jsf (JSF+Facelets Archetype) 23: internal -> jpa-maven-archetype (JPA application) 24: internal -> spring-osgi-bundle-archetype (Spring-OSGi archetype) 25: internal -> confluence-plugin-archetype (Atlassian Confluence plugin archetype) 26: internal -> jira-plugin-archetype (Atlassian JIRA plugin archetype) 27: internal -> maven-archetype-har (Hibernate Archive) 28: internal -> maven-archetype-sar (JBoss Service Archive) 29: internal -> wicket-archetype-quickstart (A simple Apache Wicket project) 30: internal -> scala-archetype-simple (A simple scala project) 31: internal -> lift-archetype-blank (A blank/empty liftweb project) 32: internal -> lift-archetype-basic (The basic (liftweb) project) 33: internal -> cocoon-22-archetype-block-plain ([http://cocoon.apache.org/2.2/maven-plugins/]) 34: internal -> cocoon-22-archetype-block ([http://cocoon.apache.org/2.2/maven-plugins/]) 35: internal -> cocoon-22-archetype-webapp ([http://cocoon.apache.org/2.2/maven-plugins/]) 36: internal -> myfaces-archetype-helloworld (A simple archetype using MyFaces) 37: internal -> myfaces-archetype-helloworld-facelets (A simple archetype using MyFaces and facelets) 38: internal -> myfaces-archetype-trinidad (A simple archetype using Myfaces and Trinidad) 39: internal -> myfaces-archetype-jsfcomponents (A simple archetype for create custom JSF components using MyFaces) 40: internal -> gmaven-archetype-basic (Groovy basic archetype) 41: internal -> gmaven-archetype-mojo (Groovy mojo archetype) Choose a number: (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41) 15: : 18
2. Project Details
Then, fill in your project details …
Define value for groupId: : com.mkyong Define value for artifactId: : projectname Define value for version: 1.0-SNAPSHOT: : 1.0 Define value for package: com.mkyong: : testing
The following files and folders structure will be created …
E:\workspace\test\projectname E:\workspace\test\projectname\src\ E:\workspace\test\projectname\src\pom.xml E:\workspace\test\projectnam\src\main\ E:\workspace\test\projectnam\src\main\resources E:\workspace\test\projectnam\src\main\webapp E:\workspace\test\projectnam\src\main\webapp\index.jsp E:\workspace\test\projectnam\src\main\webapp\WEB-INF\ E:\workspace\test\projectnam\src\main\webapp\WEB-INF\web.xml
Please refer to this Maven Standard Directory Layout article for detail explanation.
3. Pom.xml
See the generated “pom.xml” file, very clean.
<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>com.mkyong</groupId> <artifactId>projectname</artifactId> <packaging>war</packaging> <version>1.0</version> <name>projectname Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>projectname</finalName> </build> </project>
4. Done
Everything is done with just one command in Maven. The standard folder structure is created, and you can start your development now.

If when you type “mvn -version” at the command prompt you get the error: “Files was unexpected at this time.”
Then check that your JAVA_HOME variable is not enclosed in double quotes.
My environment variable JAVA_HOME, was set to “C:\Program Files (x86)\Java\jdk1.6.0_11″ (with the quotes)…
I solved the problem by removing the double quotes and set JAVA_HOME to C:\Program Files (x86)\Java\jdk1.6.0_11… all sorted!!
Hi Paul,
can i know, how to set the path in Environment variable for Maven? is it needful for set the path in environment variable for Maven. can you please help me on this problem?
Hi Paul,
How to configure POM.XML in Maven and how to set the path for Maven? Please reply me once you check my problem?
Hi Paul,
How to add JAR File for Maven?
I want EJB + WEB application development details with maven how i can generate.
First of all thank you for the tutorials.
If a run the command mvn archetype:generate, I get a list with hundreds of results and I do not know, wich archetype to use, because I do not see them all and I do not get explanations. Is there a way to get to know all the available templates.
I need a project template with jsf, hibernate, spring, mysql. How can I find an appropiate template? Is there a site to search for?
Tom
To see all archetypes list do in command line:
mvn archetype:generate > archetypes_list.txt
ctrl+C
and you will have full info in archetypes_list.txt
wow, nice trick, thanks!
great work you have done!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
thanks for this tutorial………..
If I choose any option with ‘struts2′, e.g 3 or 8, It can’t download it. Wonder how do I setup a blank struts project with Maven.
Maven is using Appfuse to generate the struts2 template , you can always see the Maven’s error detail with a “-e” option.
E.g “mvn archetype:generate -e”
It look like the Maven has some Appfuse integration problem, no worry , you can access the Appfuse site and copy the Maven’s command directly.
Here you go ~
http://appfuse.org/display/APF/AppFuse+QuickStart
You can also access the Appfuse archetypes template here
http://repo2.maven.org/maven2/org/appfuse/archetypes/