Reputation: 2980
I created a maven web project through command line procedures. I have m2e
, WTP
, tomcat
plugins installed in my Eclipse Indigo. I imported the project into eclipse through m2e plugin.
I added these in my maven settings.xml
inside <servers>
node
<server>
<id>tomcatserver</id>
<username>admin</username>
<password>adminadmin</password>
</server>
In my tomcat-users.xml
I have
<tomcat-users>
<user name="admin" password="adminadmin" roles="admin-gui,manager-gui" />
</tomcat-users>
In my pom.xml
I have
<build>
<finalName>FirstWebApp</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<server>tomcatserver</server>
<path>/FirstWebApp</path>
</configuration>
</plugin>
</plugins>
</build>
Now right click on my project -> Run as -> Maven build
Now it didn't work. i.e. under Run as -> Run on Server option didn't appear. So I
right click on project -> properties -> project facets -> selected Dynamic web module, java, javascript
Maven built the project itself. Now Run on Server
appeared. When I run the application it successfully run but the index.jsp didn't appear which is in my welcome-file-list
of web.xml
.
There is a red cross marked square appear on my project. When I clicked on Error Pages
under Deployment Descriptor header it says:
Resource '/FirstWebApp/WebContent/WEB-INF/web.xml' does not exist.
Actually it does not exist because when I created the maven project it was present in
/src/main/webapp/WEB-INF/web.xml
and it still present there. my index.jsp also present inside webapp directory.
Where is the problem ? Now I am totally confused about the directory structure of maven web project.
Can anybody please explain me about the directory structure of my web project. Here it is:
->src
->main
resources
->webapp
index.jsp
->WEB-INF
web.xml
->target
-> it's sub-directories
->WebContent
->META-INF
->WEB-INF
lib
This is giving me a pretty good headache. Please guide me that am I going the right way to develop a maven web project in eclipse ?
And Where should I put my POJOs, Servlets and other classes in this structure.
THANKS A LOT
Upvotes: 2
Views: 4011
Reputation: 54437
If you're using one of the more recent Eclipse versions (Indigo or Juno), you probably should install the m2e-wtp
plugin as well. It will bridge between the Maven configuration and the way WTP expects the project layout.
http://www.eclipse.org/m2e-wtp/
This question looks similar to what you're trying to do, it explains in more detail how to set up the project structure: Maven/Tomcat Projects In Eclipse Indigo/3.7
Upvotes: 2
Reputation: 62632
Eclipse WTP uses different conventions for file system layout than maven does. For example WTP expects that your jsp pages and config will be in WebContent, this can be changed but it will require making changes on many different project property settings.
The fastest way to solve this problem, is to create a maven web project from within eclispe that use m2e that way you will get a wtp project that is configured correctly for both maven and eclipse. Then I would copy your code into the proper locations with the new project. Anything that you would have put in web content you would put in src/main/webapp the java code goes into src/main/java. It would be a good idea to read about the maven directory conventions.
The basic concept you want to understand for getting maven and eclipse to play nice, is that both eclipse and maven will try be in charge of your project configuration and that will lead to problems. so you want to use maven as the source of all project settings that maven can set, for example maven can tell eclipse if a project is a dynamic web module or not, and the level of the java compiler to use ... etc. So for setting that maven can configure use maven. For settings that maven can not configure such as the eclipse source code formatter use the eclipse project properties to set those settings.
Another big difference between WTP and maven is that WTP expect you to have a server configured and for each project it assumes that the project has a target runtime so that things like the servlets api can be resolved. Maven on the other hand expect that your project should compile and build indepent of the app server you will run it on, so it expects you to put in dependencies on the api jars from maven central things like servlet api, jsp api jars, ... etc. And it expect those to be marked with provided scope. for example.
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<scope>provided</scope>
<version>2.2.1</version>
</dependency>
Upvotes: 2