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.
This entry was posted on Monday, January 28, 2008 at 10:54 pm and is filed under Java, Maven. Tagged: generating app with maven 2, Maven, Maven 2 project structure, Maven genapp, mvn archetype. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.






Alexwebmaster said
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
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
Vikas Hazrati said
mvn archetype:generate -DgroupId=sample.plugin -DartifactId=maven-hello-plugin -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-mojo