tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Cook" <>
Subject Re: fix...
Date Thu, 20 Jan 2000 16:27:25 GMT
thanks for the fix.

How do I now tell the Tomcat Webserver where to find my servlets? My former
URL (that worked with JSWDK 1.0.1) is
http://itccd310:8080/servlet/research.servlet.MainServlet. I get a 404 error
with Tomcat.


----- Original Message -----
From: Dustin Callaway <>
To: <>
Sent: Wednesday, January 19, 2000 11:37 PM
Subject: fix...

The following class starts the Tomcat HttpServer from
within a Java application. This allows for servlet debugging from within an
IDE. Many thanks to Jim Rudnicki for the sample code (which I just cleaned
up and simplified). Place this application in the /tomcat directory and run
it from there.

import org.apache.tomcat.server.HttpServer;

 * SimpleStartup starts the Tomcat HttpServer in a Java
 * application to allow for debugging within an IDE.
public class SimpleStartup
  public static void main(String[] args)
      HttpServer server = new HttpServer(8080, null, null);

      URL url = resolveURL("webpages");

      url = resolveURL("examples");
      server.addContext("/examples", url);

      server.start(); file://start the server
    catch (Exception e)
      System.out.println("Error: " + e);

  private static URL resolveURL(String s) throws Exception
    // if the string contains :/, then we assume that it's a real URL and do
    if (s.indexOf(":/") > -1)
        return new URL(s);

    // otherwise, we assume that we've got a file name and
    // need to construct a file url appropriatly.
    if (s.startsWith("/"))
      return new URL("file", null, s);
      String pwd = System.getProperty("user.dir");
      return new URL("file", null, pwd + "/" + s);

That's it. Register your servlet in the web.xml file, set a breakpoint in
your servlet using an IDE (JBuilder, Visual Cafe, etc.), and invoke the
servlet from a browser (execution should stop at your breakpoint). Thanks
for the tip, Jim!

Dustin Callaway

View raw message