Tuesday, May 24, 2011

Maven + Eclipse + JSP How To and How NOT To create web application



Points to observe during this tutorial

Directory Structure that eclipse creates (Figure 1) when dynamic web project is created without using maven build tool is different from that of created using Maven.It is true that different IDE's use different structure, but at last when war is build they follow same structure.This is main point that i came across when developing web applications with maven and eclipse. And, when you are making web application using maven, you have to walk through following steps carefully to become successful. but i would like to discuss some wrong paths that you may be following if you are trying to get families with maven and eclipse.

You should have following Software installed on your system to follow this tutorial.

First you should have following downloaded in order to follow this tutorial. You should have java1.6 installed o,Eclipse WTP and Maven2.2 installed on your computer. in addition to that, if you are expecting your eclipse to provide facility run maven commands , then you need to have m2eclipse plugin installed on your system. I am not going to discuss how to set these configurations on your system.

Now , you have it all :). Oky, if not , i would assume you have it all.

So, Since your goal is to use Maven as a build tool for your project. i believe you might have this doubt that, what should be the first stop.

if you are using Maven, you should follow below step first , no matter what type of project you are developing.

There are two ways to generate web project with maven automated build tool.

1. Using Command Prompt
2. Using IDE like eclipse or Ideas with maven plugin integrated in to it.

Using Command Prompt

On your command line, execute the following Maven goal:

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp

You will notice that the generate goal created a directory with the same name given as the artifactId. Change into that directory.
cd my-app 
Under this directory you will notice the following standard project structure.
Now , you have created maven web application, Very important point to notice here is that, web application project structure created by maven is different form project structure created for a web application using eclipse IDE without using Maven. Keep this point in mind, i will later come to this point and explain how this difference could affect development activities.
Same project structure can be created if you are using m2eclipse plugin.   .