How to generate Maven based Java-J2EE Project using Archetype?

generate maven based java/j2ee project using archetype

Weaving a Nest (dkeats, Flickr)

Basically Maven tool used to apply patterns to a project’s build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices.  Maven is essentially a project management and comprehension tool and as such provides a way to managing

  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Releases
  • Distribution

In this article I will be describing a way to generate maven based Java-J2EE project using archetype.


What is Maven Archetype?

In a simple note, 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.  Using archetypes provides a great way to enable developers quickly in a way consistent with best practices employed by your project or organization.

Exclusive list of Maven Archetypes(around 607 types+) I have gathered it here!  Creating Maven Archetype for your requirement, please refer  this page.


Benefits of Maven Archetype

Maven archetype is best channel to bring patterns and industry best practices to your Java/J2EE development/existing project.

  • Get your developers up and running as quickly as possible by providing a sample project that demonstrates many of the features of Maven
  • In a matter of seconds a new developer can have a working Maven project to use as a jumping board to make use more of the features in Maven
  • Archetype is a mechanism additive and by that 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

“There is no faster way to get started with Java/J2EE project than using these archetypes!”

For Example: To standardize Java/J2EE development within your organization so you may want to provide archetypes for EJBs, or WARs, or web services, etc.  Once these archetypes are created and deployed in your organization’s repository they are available for use by all developers within your organization.


Generate Project using Maven Archetype?

Now let’s see How to generate Maven based Java-J2EE Project using Archetype?.  I will be describing a steps in simple way, however if you have any clarification or query please leave comment below.

Step 1

Start with below maven command

Step 2

Now maven will be downloading necessary POM files and Jar into your Local Maven Repo

Step 3

Maven will display all the available archetype (while this execution I have got 607 archetypes+) from Maven Repository.  For illustration purpose I will using maven quick start archetype.

Note: Default value of Archetype is “197: remote -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.)”

Step 4

Now maven will display given properties for confirmation, provide Y as a input

Step 5

Maven will create a project as given in the -DartifactId parameter and display you the BUILD SUCCESSFUL information


Result

That’s it, you have successfully generated Java-J2EE project using Maven archetype.


Downloads

This article generated sampleapplication has been checked-in to GitHub

Also downloadable zip archive available click here!

Reference: maven.apache.org