How to create a modularized maven project in eclipse
Tech-Today

How to create a modularized maven project in eclipse


I've just noticed that it's easier to do this now on eclipse-jee-indigo, no need to use the console :-)

I'll try to make this write up short, but I guess it will not be.

So first, you should have the ff installed (if you don't know how - just google them):
1.) eclipse-jee-indigo with m2e plugin installed (http://download.eclipse.org/technology/m2e/releases)
2.) maven 3.0.4
3.) should I mention jdk, jre?

Here are the steps:

1.) Create a new java project ipiel and delete the src folder.

2.) Convert the project into maven type.

Use the ff settings:

3.) Create a new maven project using the eclipse wizard, RIGHT CLICK ipiel project->New->Other, filter by maven.

4.) Tick, create a simple project

4.) Click next and enter the ff settings:
5.) Click finish. You should see the ff screen:
6.) Create a new maven project ipiel-portal, and repeat from 3-5. Use the ff settings:

7.) Now let's add a dependency ipiel-models to ipiel-portal, by opening the pom.xml file->dependencies tab->add, in the enter groupid... enter ipiel-models to make the process easier:
8.) Let's start adding test classes :-)

9.) In ipiel-models project, let's add class User:


package com.ipiel.models;

public class User {
private String name;

public User() {
name = "Ipiel";
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
10.) Let's add a class with main method to test the dependency in ipiel-portal:
package com.ipiel.portal;

import com.ipiel.models.User;

public class Runner {
public static void main(String args[]) {
new Runner();
}

public Runner() {
User u = new User();
System.out.println("Hello " + u.getName());
}
}
11.) Now, let's add the 2 projects (ipiel-models, ipiel-portal) as module to ipiel:

-ipiel
--ipiel-portal
---ipiel-models
---ipiel-your-lib
11.a) Click on ipiel project pom.xml, and in Overview Tab, click Modules, check both:
12.) With all the projects and codes in setup, try calling Maven install in ipiel project:
And as you see, it should output the build success message.

13.) To test if the dependency works, run ipiel-portal as a Java Application, right click on the project Run As->Java Application, it should output "Hello Ipiel".

14.) Now what if you want to add other dependencies for example PMD (eclipse plugin - http://pmd.sourceforge.net/eclipse) to check code (or later FindBugs or Cobertura)

15.) Using http://mvnrepository.com, search for PMD. I've found: http://mvnrepository.com/artifact/pmd/pmd, click version 4.3 and copy the dependency settings to ipiel-portal project's pom.xml. Another shortcut way is in select dependency window, type pmd like we did earlier:

16.) Now to download the pmd jar, right click on ipiel-portal project->Run As->Maven generate-sources, after a successful run you should see pmd-4.3.jar in your Maven Dependencies:
Note: actually pmd could be anything, I just couldn't think of that anything right now :-). Could be log4j, joda-time, hsqldb, etc :-). You get the point?




- How To Create A Modularized Ear Project In Maven
This post is one way of creating a typical javaee6 maven project that contains ear, web, ejb and api. The output of course is an ear file that contains (web, ejb and api). How it looks like (assuming our top project is named ipiel): +ipiel  +ipiel-ear...

- How To Setup A Dns Server On Ubuntu 12.04
This tutorial will help you in setting up a dns gateway in your ubuntu machine (I'm using 12.04 version, not sure if this would work on others). First we need to install bind9, which is a dns server: sudo apt-get install bind9 Open /etc/bind/named.conf.local...

- How To Encode And Decode A Json Encrypted String In Java
This tutorial requires the use of apache commons and jackson libraries. For example I have a highly confidential string and I want to send it over the net, of course normally I want to encrypt it. And one of the method we can send this encrypted string...

- How To Setup Findbugs With Maven On Eclipse
Before you proceed with this exercise, it's required to check my blog on how to create a modular maven project. http://czetsuya-tech.blogspot.com/2012/04/how-to-create-modularized-maven-project.html 1.) In this link you will...

- Eclipse-rcp Calling A Command With Parameter In Code
In case you come up with the same situation as mine, here's how I've done it. 1.) in your eclipse-rcp's project's plugin.xml create a new command with a parameter, set the ids Example -commandId: org.ipiel.demo.commands.click -commandParameterId:...



Tech-Today








.