Java project archetype maven
Creating a project from an archetype involves three steps:
- prepare repository reference
- the selection of the archetype,
- the configuration of that archetype,
- the effective creation of the project from the collected information.
Usage
In general an archetype is coming from a remote repository. If that repository can be reached via the setup of your Maven, you’re ready to start. In cases where the repository is not managed and you want to refer to it directly, you have to add the repository to your settings.xml. Read the small set of instructions on the Archetype Repository-page.
Calling archetype:generate the plugin will first ask to choose the archetype from the internal catalog. Just enter the number of the archetype.
It then asks you to enter the values for the groupId, the artifactId and the version of the project to create and the base package for the sources.
It then asks for confirmation of the configuration and performs the creation of the project.
In the following example, we selected the quickstart archetype (default value, which is 15 here but may vary depending on the repository content) and set groupId to com.company, artifactId to project, version to 1.0 and package to com.company.project.
$ 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:create] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] [archetype:generate] Choose archetype: 1: internal -> org.appfuse.archetypes:appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF) 2: internal -> org.appfuse.archetypes:appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC) 3: internal -> org.appfuse.archetypes:appfuse-basic-struts (AppFuse archetype for creating a web application with Hibernate, Spring and Struts 2) 4: internal -> org.appfuse.archetypes:appfuse-basic-tapestry (AppFuse archetype for creating a web application with Hibernate, Spring and Tapestry 4) 5: internal -> org.appfuse.archetypes:appfuse-core (AppFuse archetype for creating a jar application with Hibernate and Spring and XFire) 6: internal -> org.appfuse.archetypes:appfuse-modular-jsf (AppFuse archetype for creating a modular application with Hibernate, Spring and JSF) 7: internal -> org.appfuse.archetypes:appfuse-modular-spring (AppFuse archetype for creating a modular application with Hibernate, Spring and Spring MVC) 8: internal -> org.appfuse.archetypes:appfuse-modular-struts (AppFuse archetype for creating a modular application with Hibernate, Spring and Struts 2) 9: internal -> org.appfuse.archetypes:appfuse-modular-tapestry (AppFuse archetype for creating a modular application with Hibernate, Spring and Tapestry 4) 10: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (A simple J2EE Java application) 11: internal -> org.apache.maven.archetypes:maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade) 12: internal -> org.apache.maven.archetypes:maven-archetype-mojo (A Maven Java plugin development project) 13: internal -> org.apache.maven.archetypes:maven-archetype-portlet (A simple portlet application) 14: internal -> org.apache.maven.archetypes:maven-archetype-profiles () 15: internal -> org.apache.maven.archetypes:maven-archetype-quickstart () 16: internal -> org.apache.maven.archetypes:maven-archetype-site-simple (A simple site generation project) 17: internal -> org.apache.maven.archetypes:maven-archetype-site (A more complex site project) 18: internal -> org.apache.maven.archetypes:maven-archetype-webapp (A simple Java web application) 19: internal -> org.apache.struts:struts2-archetype-starter (A starter Struts 2 application with Sitemesh, DWR, and Spring) 20: internal -> org.apache.struts:struts2-archetype-blank (A minimal Struts 2 application) 21: internal -> org.apache.struts:struts2-archetype-portlet (A minimal Struts 2 application that can be deployed as a portlet) 22: internal -> org.apache.struts:struts2-archetype-dbportlet (A starter Struts 2 portlet that demonstrates a simple CRUD interface with db backing) 23: internal -> org.apache.struts:struts2-archetype-plugin (A Struts 2 plugin) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 15: Choose org.apache.maven.archetypes:maven-archetype-quickstart version: 1: 1.0-alpha-1 2: 1.0-alpha-2 3: 1.0-alpha-3 4: 1.0-alpha-4 5: 1.0 6: 1.1 Choose a number: 6: Define value for groupId: : com.company Define value for artifactId: : project Define value for version: : 1.0 Define value for package: : com.company.project Confirm properties configuration: groupId: com.company artifactId: project version: 1.0 package: com.company.project Y: : [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating OldArchetype: maven-archetype-quickstart:RELEASE [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: com.company [INFO] Parameter: packageName, Value: com.company.project [INFO] Parameter: package, Value: com.company.project [INFO] Parameter: artifactId, Value: project [INFO] Parameter: basedir, Value: /home/local/rafale/projects/tmp [INFO] Parameter: version, Value: 1.0 [INFO] OldArchetype created in dir: /home/local/rafale/projects/tmp/project [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 54 seconds [INFO] Finished at: Fri Aug 26 23:01:01 GMT 2011 [INFO] Final Memory: 10M/25M [INFO] ------------------------------------------------------------------------
Here’s the resulting tree of the created project
$ tree project project |-- pom.xml `-- src |-- main | `-- java | `-- com | `-- company | `-- project | `-- App.java `-- test `-- java `-- com `-- company `-- project `-- AppTest.java 11 directories, 3 files
Filtering to reduce archetype list
As of version 2.1, you can reduce the list of displayed archetypes. The filter use the following format: [groupId:]artifactId. If you use single word without :, only artifactId will be checked. The filtering applied is a case sensitive contains on the artifactId (and groupId if set).
$ mvn archetype:generate -Dfilter=org.apache:struts
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): org.apache:struts
Copyright ©2007–2021 The Apache Software Foundation. All rights reserved.
Java project archetype maven
- Apache /
- Maven /
- Archetypes /
- Maven Archetypes
- | Last Published: 2018-12-09
- Version: 1.4
- Overview
- Introduction
- License
- Download
- Modules
- Maven Archetype Archetype
- Maven Simple J2EE Archetype
- Maven Plugin Archetype
- Maven Plugin Site Archetype
- Maven Portlet Archetype
- Maven Quickstart Archetype
- Maven Simple Project Archetype
- Maven Site Archetype
- Maven Archetype for Simple Site
- Maven Site Skin Archetype
- Maven Webapp Archetype
- Project Documentation
- Project Information
- About
- Summary
- Dependency Information
- Project Modules
- Team
- Source Code Management
- Issue Management
- Mailing Lists
- Dependency Management
- Dependency Convergence
- CI Management
- Plugin Management
- Plugins
- Distribution Management
Maven Archetypes
Maven provides several archetype artifacts:
Archetype ArtifactIds Description maven-archetype-archetype An archetype to generate a sample archetype. maven-archetype-j2ee-simple An archetype to generate a simplifed sample J2EE application. maven-archetype-plugin An archetype to generate a sample Maven plugin. maven-archetype-plugin-site An archetype to generate a sample Maven plugin site. maven-archetype-portlet An archetype to generate a sample JSR-268 Portlet. maven-archetype-quickstart An archetype to generate a sample Maven project. maven-archetype-simple An archetype to generate a simple Maven project. maven-archetype-site An archetype to generate a sample Maven site which demonstrates some of the supported document types like APT, Markdown, XDoc, and FML and demonstrates how to i18n your site. maven-archetype-site-simple An archetype to generate a sample Maven site. maven-archetype-site-skin An archetype to generate a sample Maven Site Skin. maven-archetype-webapp An archetype to generate a sample Maven Webapp project. Copyright ©2002–2018 The Apache Software Foundation. All rights reserved.
What is Archetype?
In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made. The name fits as we are trying to provide a system that provides a consistent means of generating Maven projects. Archetype will help authors create Maven project templates for users, and provides users with the means to generate parameterized versions of those project templates.
Using archetypes provides a great way to enable developers quickly in a way consistent with best practices employed by your project or organization. Within the Maven project, we use archetypes to try and get our users up and running as quickly as possible by providing a sample project that demonstrates many of the features of Maven, while introducing new users to the best practices employed by Maven. In a matter of seconds, a new user can have a working Maven project to use as a jumping board for investigating more of the features in Maven. We have also tried to make the Archetype mechanism additive, and by that we mean allowing portions of a project to be captured in an archetype so that pieces or aspects of a project can be added to existing projects. A good example of this is the Maven site archetype. If, for example, you have used the quick start archetype to generate a working project, you can then quickly create a site for that project by using the site archetype within that existing project. You can do anything like this with archetypes.
You may want to standardize J2EE development within your organization, so you may want to provide archetypes for EJBs, or WARs, or for your web services. Once these archetypes are created and deployed in your organization’s repository, they are available for use by all developers within your organization.
Using an Archetype
To create a new project based on an Archetype, you need to call mvn archetype:generate goal, like the following:
Provided Archetypes
Maven provides several Archetype artifacts:
Archetype ArtifactIds Description maven-archetype-archetype An archetype to generate a sample archetype project. maven-archetype-j2ee-simple An archetype to generate a simplifed sample J2EE application. maven-archetype-mojo An archetype to generate a sample a sample Maven plugin. maven-archetype-plugin An archetype to generate a sample Maven plugin. maven-archetype-plugin-site An archetype to generate a sample Maven plugin site. maven-archetype-portlet An archetype to generate a sample JSR-268 Portlet. maven-archetype-quickstart An archetype to generate a sample Maven project. maven-archetype-simple An archetype to generate a simple Maven project. maven-archetype-site An archetype to generate a sample Maven site which demonstrates some of the supported document types like APT, XDoc, and FML and demonstrates how to i18n your site. maven-archetype-site-simple An archetype to generate a sample Maven site. maven-archetype-webapp An archetype to generate a sample Maven Webapp project. For more information on these archetypes, please refer to the Maven Archetype Bundles page.
What makes up an Archetype?
Archetypes are packaged up in a JAR and they consist of the archetype metadata which describes the contents of archetype, and a set of Velocity templates which make up the prototype project. If you would like to know how to make your own archetypes, please refer to our Guide to creating archetypes.