You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Dustin Callaway <ca...@sourcestream.com> on 2000/01/20 05:37:50 UTC
SimpleStartup.java fix...
The following SimpleStartup.java 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;
import java.net.URL;
/**
* 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)
{
try
{
HttpServer server = new HttpServer(8080, null, null);
URL url = resolveURL("webpages");
server.getContextManager().setDocumentBase(url);
url = resolveURL("examples");
server.addContext("/examples", url);
server.start(); //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 nothing
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);
}
else
{
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
(callaway@sourcestream.com)
Re: SimpleStartup.java fix...
Posted by James Cook <ji...@iname.com>.
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.
thanks,
jim
----- Original Message -----
From: Dustin Callaway <ca...@sourcestream.com>
To: <to...@jakarta.apache.org>
Sent: Wednesday, January 19, 2000 11:37 PM
Subject: SimpleStartup.java fix...
The following SimpleStartup.java 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;
import java.net.URL;
/**
* 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)
{
try
{
HttpServer server = new HttpServer(8080, null, null);
URL url = resolveURL("webpages");
server.getContextManager().setDocumentBase(url);
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
nothing
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);
}
else
{
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
(callaway@sourcestream.com)
Re: SimpleStartup.java fix...
Posted by co...@costin.dnt.ro.
Thanks, I'll commit your SimpleStartup.
I'll just change it to use ContextManager directly, HttpServer might
go away.
Costin
> 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
> (callaway@sourcestream.com)
>