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


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

Maven error Annotations are not supported in -source 1.3

Importing packages to eclipse added by maven to java web project

Using mvn for creating and running a boilerplate minimal java application

  1. Victor Manuel Nuñez Guzman

    when i execute mvn war:war i have the following message:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.5:war (default-cli) on project MavenEclipseJ2EE: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

    [Help 1]

    1. gullele

      hey Victor, sorry for the late response,
      Are you still having the problem?
      It looks class path issue as I can see it..

      1. Victor Manuel Nuñez Guzman

        thanks for the reply … now I am NOT with this … the original problem was that I couldn’t open a project on another computer …

Leave a Reply

Your email address will not be published. Required fields are marked *