views:

1151

answers:

3

I am trying to get a simple helloworld test project going so I can build upon it. I am using Java EE with maven in Eclipse and am getting a Requested reseource is not available error from tomcat in my web browser.

Right now all I have is a test jsp page to print Hello World which is all I am trying to get working. I created a maven project using the command mvn archetype:generate .. to generate the project structure which I then imported into Eclipse. I then added a dynamic web facet to the project.

The following is what my web.xml file looks like:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

How do I get tomcat to pick up my index.jsp file so that I can display it? Am I missing something in my web.xml file? I have a tomcat server running from within eclipse so this is not the problem. Would I need a servlet mapping entry in my web.xml? I am just really lost as to how this all fits together. Any help would be great.

This is the command I used to generate the maven project:

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

Thanks

A: 

Can you post the logs from tomcat to see if there are any specific errors in there. Also, you can take a look at the following page that shows you how to connect eclipse to Tomcat and how to publish projects from eclipse to Tomcat. The tutorial goes through a simple Hello World example similar to the one you are trying to develop.

http://www.ibm.com/developerworks/library/os-eclipse-tomcat/index.html

Waleed Al-Balooshi
+2  A: 

I created a maven project using the command mvn archetype:generate ... to generate the project structure which I then imported into Eclipse. I then added a dynamic web facet to the project.

You shouldn't have to add any facet, things should just work if your project has a packaging of type war.

It would thus have been nice to provide the full command you used to create your project with the archetype plugin. Did you use the maven-archetype-webapp archetype? Did you ran something like that:

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp \
  -DgroupId=my.group.id -DartifactId=my-artifact -Dversion=1.0-SNAPSHOT

If not, then be sure that your pom has a <packaging>war</packaging> and that you use the default structure for a war project (see Usage for an example).

Then, what plugin are you using for the Eclipse integration? How did you import the project into Eclipse?

If you are using the maven-eclipse-plugin (if you ran eclipse:eclipse), then you need to configure it for WTP support. You need to pass the wtpversion on the command line (or to configure the plugin in the POM):

mvn -Dwtpversion=2.0 eclipse:eclipse

If you are using m2eclipse, then just import your project as a Maven Project (right-click the Package Explorer then Import... > Maven Projects).

In both case, your project should be recognized as a Dynamic Web Module that you can Run on Server). There is nothing manual to configure for this (no facet to add).

Update: Did you install the Maven Integration for WTP (Optional) when installing m2eclipse?

Pascal Thivent
I am using m2eclipse and I did import the project as a Maven project. It was not recognized by default as a dynamic web project which is why I had to add that facet to the project. I wonder why this was..
james
I tried importing the maven project again. When I try to add the resource to the Tomcat server in eclipse, the imported project doesn't show up. This is why I originally realized that I had to add the dynamic web java project facet to the project. Do you have any ideas what I may be doing wrong?
james
@james I just added another suggestion (maybe you didn't install the WTP support in m2eclipse).
Pascal Thivent
wow..you are good. That worked. Thanks for your help!
james
A: 

Here are somethings you can try:

a) Make sure the URL is correct - It should be something like this http://localhost:8080/DEPLOY_NAME/index.jsp where DEPLOY_NAME is usually your PROJECT_NAME *see below.

b) Make sure the project was deployed - Look in the Servers tab, under the server name (e.g. Tomcat v6.0 Server at localhost) and look for your project/deploy_name to be listed there, if it isn't then you need to run the project so that it's on the server. To do that, stop the server using the red square in the Servers tab, then select the project in the Navigator and click the Green Run button, selecting Run on Server. That will restart the server and deploy the project.

C) Make sure the deploy name is what you expect it to be - If the DEPLOY_NAME is different that the Project name then you need to update the URL you are using. To check, go back to the Servers tab, and under the server name (e.g. Tomcat v6.0 Server at localhost) see what Tomcat deployed WebApp as. If this name is different than the project name you have two choices : Rename it or remember to use the Deploy name in the URL when testing. To rename it, you change it in ../.settings/org.eclipse.wst.common.component, then look for the XML tag named and the XML tag .

eSniff