2013-05-14

Generate a maven project

This series of posts will try to show the way that a JEE6 project should be organized in terms of modules and physical organization.

The tools and technologies used in this sample project are:
  • JEE 6 
  • HTML 5
  • JBoss A.S. 7
  • Maven
  • JUnit
  • Jenkins
  • IDE Netbeans 7.3
So, why is this series of posts going to do different from a lot of other posts that talk about the same issues? Maybe it is that it will try to show a way to organize the project in modules and start a discussion about the ways to do it. Yes, there are a lot of software engineering, architecture or technical books that have a deep discussion about this, but almost all of them fail in terms of practical and straight ways to show a "how to do it", so there is the why.

The sample chosen for this blog will be a user management module (yes, module), a big enough sample to show concepts like modularization, unit testing, and other concepts that I am trying to expose in here. The explicit requirements will be shown in a future post as "user histories" to illustrate some Agile and TDD concepts.

As you can see this blog is a bit ambitious, but I do it because it is the only way that lot of isolated concepts get clear and be useful to the software developers. There is a lot of work to do, so let's start.

Creating the initial project

Maven is becoming the defacto tool for building and deploying tasks, slowly replacing our good and well known ant system.

What I like about maven is the fact that it is IDE agnostic, you can create a maven project in the IDE flavour you prefer and open it everywhere else. The tool tries to put order in the way the projects are organized and avoids the "reinventing the wheel" symptom on every new project. But in what maven shines is in avoiding us the libraries management nightmare through a repository whose main goal is to centralize the developed artifacts (i.e. jars) and its versions.

In maven, a project is usually intended to generate a deployable unit whose namespace is composed of three elements: A group identifier, an artifact identifier and a version number. The first one is intended to identify the organization behind the project, the second will identify the project name  and the third one the version of that artifact in time. This is a typical project configuration:

<groupId>org.loxageek</groupId>
<artifactId>security</artifactId>
<version>1.0-SNAPSHOT</version>

Once installed maven in your box, it is easy to create a new project. For instance to create the project identified previously you can execute the following command in your command line, remember to change to your sandbox directory.

$ mvn archetype:generate -DgroupId=org.loxageek -DartifactId=security -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

This command will create a project directory structure under security as shown in the next scheme:


And that is it, you have now a basic project template to start coding as soon as you want opening it in the IDE you like it more.

The next post will unveil some of the inner basic features of maven.

No comments: