Friday, November 19, 2010

Generating project structure using Maven

To generate the project structure using maven, we use maven's archetype mechanism. In Maven, an archetype is a template of a project which is combined with some user input to produce a working Maven project that has been tailored to the user's requirements (This help you generate the desired project structure depending on the application that you are trying to build.)


Following I have shown how you can use maven to generate a project structure for simple java application.


mvn archetype:create -DgroupId=org.wso2.carbon -DartifactId=sample -DarchetypeArtifactId=maven-archetype-quickstart


This will generate a project structure as follows



|-- sample
|   |-- pom.xml
|   `-- src
|       |-- main
|       |   `-- java
|       |       `-- org
|       |           `-- wso2
|       |               `-- carbon
|       |                   `-- App.java
|       `-- test
|           `-- java
|               `-- org
|                   `-- wso2
|                       `-- carbon
|                           `-- AppTest.java



This will create App.java with package name as org.wso2.carbon and create default pom.xml as well as AppTest.java class for unit testing.

1 comment:

zygimantus said...

You need to use mvn archetype:generate -DgroupId=org.wso2.carbon -DartifactId=sample -DarchetypeArtifactId=maven-archetype-quickstart (generate instead of create). NOTE: Apache Maven 3.3.3