Thursday, April 29, 2010

Understanding Maven Archetype

The Archetype plugin allows you to use a pre-defined pattern for project development. You can have a pattern for different kind of project (Hibernate/Spring, JSF or JBoss Service Archive). You can have 249 choices of Archetype using this command from the CLI:

mvn archetype:generate.

Choice #15 is a quick start template, it sets up a simple JEE application embedded with Apache Jetty application server.

Getting back to Hibernate tutorial, they recommand you to use mvn archetype:create to build your template.

create goal has been deprecated as of version 2-0 of the plugin although it still works. To create the template, you can start running the goal and define groupId and artifactId:

mvn archetype:create -DgroupId=org.hibernate.tutorials -DartifactId=hibernate-tutorial

The Archetype plugin creates the following project template:

hibernate-tutorial

--src
--main
--java
--org
--hibernate
--tutorials
--App.java
--test
--java
--org
--hibernate
--tutorials
--AppTest.java



As you can see, the groupId property defines the package structure of the project, the artifactId property is the root folder of the application. A test folder is also generated with the same package structure and a Test file.
The pom.xml file is created at the same level as src. If you edit the file, you will see that a dependency is created for JUnit v3.8.1.

No comments: