Maven J2EE Eclipse: Hello world in J2EE and Maven on Eclipse

Step by step tutorial on J2EE and Maven on IDE Eclipse

Here is a simple yet basic tutorial for a J2EE application using maven and Eclipse from the scratch showing you step by step.

This tutorial assumes you know the basics of Maven and J2EE. This is just a step by step tutorial to show the marriage of the two.

Also, it is assumed that you have installed maven and tomcat on your machine which are fairly easy to do with simple googling.

Lets Start

1. Create simple Hello world module on Eclipse
1.a Open Eclipse Go to file->new->Dynamic Web Project
1.b Name the project as MavenEclipseJ2EE and hit Finish

We have finished the first step.

Now, maven expects some kind of folder structure. Well, you can do it in your own way and make extra configuration, or you can accept what is accepted as standard and have fun.. I go with the standard maven directory structure.

Here is the maven structure


src/main/java
src/main/resource
src/main/webapp

These are going to the source folders. So lets create them.

2. Creating source folders that are acceptable by maven

2.a Go to terminal or how ever you would create folders and create the folders as:

MavenEclipseJ2EE/src$ mkdir main
MavenEclipseJ2EE/src$ mkdir main/java
MavenEclipseJ2EE/src$ mkdir main/resources
MavenEclipseJ2EE/src$ mkdir main/webapp

2.b Go back to Eclipse, select the project and hit F5 or right click on Project and hit refresh. You will see the newly created folders under src

2.c Right click on the project, select properties, select build path and hit source tab

2.d You would see the previous source folder there. Select it and hit remove to remove it. We do this since we are changing the source folders

2.e Then hit the button add folder, expand src, expand main and select the java, resources and webapps only. Hit OK and hit OK again to finish creating source files.

Cool, so our folder structure is ready for Maven. Now lets move to the maven itself.

Maven relies highly on the pom.xml file that we would put on the project root folder. Lets do that.

Continue to part two