c0nnexx10n : C0nnect1ng L1fe w1th Techn010gy

Byte by Byte Impressions on Technology, People and Process !

QuickTip : Generating project structure using Maven

Posted by vikashazrati on Monday, January 28, 2008

When you are starting a new project it is very easy to get started if the project structure can be built for you. Maven provides a plugin called maven-archetype-plugin which can help you generate the desired project structure depending on the application that you are trying to build.

The Archetype Plugin allows the user to build archetype containers. These archetype containers contains the pom, default source, test, resources, test-resources, and site-resources files in a specific directory structure. The content of the pom, the default files, and the directory structure depends on the what archetype container was built.

To create a simple java application you can use

mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-quickstart

Likewise to create a webapp use something like this

mvn archetype:create -DgroupId=org.vh.hibjpa -DartifactId=hibernatejpa_webapp -DarchetypeArtifactId=maven-archetype-webapp

we would end up with a structure like this

.
 |-- src
 |   `-- main
 |       `-- java
 |           |-- resources
 |           |-- webapp
 |           |   `-- WEB-INF
 |           |       `-- web.xml
 |           `-- index.jsp
  `-- pom.xml

There are several archetype containers available. A full list of containers shows 10 of them. List of some more useful archetypes which are not present on the apache site.

Once the project is generated go into the project and type mvn eclipse:eclipse, this would make it work with the eclipse ide. You would have to add the M2_REPO variable to the eclipse environment. If the archetype container is not present in your repository then it is downloaded once the archetype:create is executed.


AddThis Social Bookmark Button

3 Responses to “QuickTip : Generating project structure using Maven”

  1. Alexwebmaster said

    Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

  2. Vikas Hazrati said

    For creating a mojo plugin project use

    mvn archetype:create \
    -DgroupId=sample.plugin \
    -DartifactId=maven-hello-plugin \
    -DarchetypeGroupId=org.apache.maven.archetypes \
    -DarchetypeArtifactId=maven-archetype-mojo

  3. Vikas Hazrati said

    mvn archetype:generate -DgroupId=sample.plugin -DartifactId=maven-hello-plugin -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-mojo

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>