Maven 2 is an elegant project build/management framework that follows the mantra of "Convention over Configuration" made popular by the "Ruby on Rails" community. The premise is that by following the conventions laid out by Maven 2, a developer can very quickly put together a project that can be compiled, tested and packaged in a meaningful way and even get code coverage to boot!

In order to create a client/server java application in maven we should create a multi-modules project. The steps would involve:

  1. create a parent project with the maven-archetype-quickstart

  2. cd into the parent project directory:

     

    • edit the pom.xml to change the packaging from jar to pom.

pom is basically a container of submodules, in our case we will have two submodules: the client and the server modules. Each submodule will be represented by a subdirectory in the same directory as pom.xml with pom packaging. Thus, within the project structure we will create artifacts (modules) with jar packaging. Maven will build everything into /target subdirectories of each module. So after mvn install look into target subdirectories in a module with jar packaging.

    • remove the src directory.

If you are using the eclipse IDE, you need to go in the project to: "Properties → Source" and remove all the source folders. Next, you need to update the project: "Maven → Update Project...".

 

  1. create a client project from the parent directory with the maven-archetype-quickstart. If you are using the eclipse IDE, you can specify to create a "Maven Module".

  2. create a server project from the parent directory with the maven-archetype-quickstart. If you are using the eclipse IDE, you can specify to create a "Maven Module".

The next steps are not necessary if you create the server and client projects with the option create a "Maven Module" in the eclipse IDE.

  1. In the pom.xml of each module, specify the parent project directory as its Parent: "Overview → Parent → Click in icon Select Parent".
  2. Finally, add the two modules in the pom.xml of the parent project directory. "Overview → Modules → Add".

Following this configuration allows us to specific all the dependencies in the pom.xml of parent project directory: "Dependencies → Add" and reuse them in the other two modules by specifing it in the dependencies of the pom.xml: "Dependencies → Add → Fill the Group Id and Artifact Id of the parent project directory".

 

Pin It

Add comment


Security code
Refresh