Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

n00b cannot get jar files to work.

Michael Labhard

2004-05-27


How do I get jar files to work?

Learning Tomcat I have a simple "HelloServlet" class. When compiled and the
class file is inserted into the directory

 /opt/tomcat/webapps/test/WEB-INF/classes/example

and the web.xml file given below is placed in

 /opt/tomcat/webapps/test/WEB-INF/

and tomcat is restarted then the url

http://localhost:8080/test/hello

page reads:

 Hello, world!

But if the same class is placed in a jar file and this jar file is inserted
into any of the following directories and given permissions tomcat:tomcat

 /opt/tomcat/webapps/test/WEB-INF/lib
 /opt/tomcat/common/lib
 /opt/tomcat/shared/lib

when tomcat is restarted and the same url is addressed first there is

 < Blank page >

the second time the page is refreshed there is

 Status 500:
 javax.servlet.ServletException: Wrapper cannot find servlet class

 example.HelloServlet or a class it depends on

and the third and all subsequent times the page is refreshed there is

 Status 400:
  Servlet hello is not available

How do I get jar files to work? Thank you.

-- Michael

Appendix:

web.xml file:

<?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>hello</servlet-name>
  <servlet-class>example.HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
  <url-pattern>/hello</url-pattern>
  <servlet-name>hello</servlet-name>
</servlet-mapping>
</web-app>


HelloServlet.java:

package example;

import java.io.*;
import java.util.*;

import javax.servlet.http.*;
import javax.servlet.*;

public class HelloServlet extends HttpServlet {
public void doGet (
    HttpServletRequest    req,
    HttpServletResponse   res
  ) throws ServletException, IOException
{
  res.setContentType("text/html");
  PrintWriter pw = res.getWriter();

  pw.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0
Transitional//EN\">");
  pw.println();
  pw.println("<head>");
  pw.println("<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=ISO-8859-1\">");
  pw.println();
  pw.println("<!-- The Servlet expression tags interpolate script variables
into the HTML -->");
  pw.println();
  pw.println("<title>Hello, world!</title>");
  pw.println("</head>");
  pw.println();
  pw.println("<body bgcolor=white>");
  pw.println();
  pw.println("<h1>Hello, world!</h1>");
  pw.println();
  pw.println("</body>");
  pw.close();
}

public HelloServlet() {}
}


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.