no

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 ...

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?

Related

source-code-management 7025753160707503803

Post a Comment Default Comments

item