artaxerxe
artaxerxe

Reputation: 6411

How to run an app in Tomcat?

I have put my project in tomcat_home/webapps/ directory. The structure is : project_name/WEB-INF/classes. in WEB-INF i have put my web.xml descriptor. The problem is that when i try to run the application, it doesn't find the files. The error is:

The requested resource () is not available.

My web.xml content is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

    version="2.4">
<servlet>
   <servlet-name>Chapter1 Servlet</servlet-name>
   <servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
   <servlet-name>Chapter1 Servlet</servlet-name>
   <servlet-url>/Serv1</servlet-url> 
</servlet-mapping>
</web-app>

I have also restarted the server, but it doesn't want to work. Any suggestions?

Upvotes: 1

Views: 394

Answers (5)

duffymo
duffymo

Reputation: 308763

You need to throw what you have away, start again and go through this very carefully:

http://tomcat.apache.org/tomcat-6.0-doc/appdev/index.html

What have you learned so far?

  1. Your servlet .class needs to be in a package. You should see WEB-INF/classes/com.foo.Bar.class if your class is Bar.jar with a package com.foo; at the top
  2. Package your app into a WAR named MyApp and put it in /webapps to deploy it.
  3. The URL needs to be http://localhost:8080/MyApp/Bar if you map com.foo.Bar to /Bar

Forcing people to make suggestions, and repeating that "it doesn't work", isn't going to get you where you need to be.

Upvotes: 1

Adrian Regan
Adrian Regan

Reputation: 2250

Does your servlet have a namespace. In the tag you need to fully qualify the Ch1Servlet class, i.e. my.code.Ch1Servlet

--- Additional after reading comments -----

Ok, try this. Create a context for your webapp. Create a file named project_name.xml and put the following in it:

<Context path="/Serv1" docBase="webapps/project_name" 
         reloadable="true" debug="0" privileged="true">
</Context>

Now put the xml file in the webapps directory.

If you are deploying a WAR then replace the docBase as "webapps/project_name.war"

Upvotes: 1

shinynewbike
shinynewbike

Reputation: 2352

How about http://localhost:8080/Serv1 without the webapp name in the URL?

Upvotes: 0

lucrussell
lucrussell

Reputation: 5160

It looks like you need to put your servlet in a package, e.g. com.me.Ch1Servlet. Then change the servlet-class declaration to <servlet-class>com.me.Ch1Servlet</servlet-class>

Upvotes: 0

Chris J
Chris J

Reputation: 9252

If you are using the default server.xml that comes with Tomcat, you should not have to alter it to just get your Web app running. Have you tried accessing it from the following URL: http://localhost:8080/project_name/

Upvotes: 0

Related Questions