You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Eric Holk <er...@gmail.com> on 2005/09/30 19:10:06 UTC

Embedded Tomcat

I'm working on a project where I would like to run a simple web front end
for it. To save the time of implementing my own HTTP server I'd like to
embed Tomcat. I've read several documents on how to do this, and I've
managed to get Tomcat running inside my program. However, all the examples
I've seen show how to load a WAR file and use that as a web application. If
it's possible, I'd rather just have a sevlet class inside my program that
Tomcat uses rather than having an external web application. I haven't found
any examples for how to do this, and I haven't been able to figure it out
from the JavaDocs. Does anyone have ideas for how to do this?

Thanks,
Eric Holk

Re: Embedded Tomcat

Posted by Rick Knowles <ri...@knowleses.org>.
Eric Holk wrote:

>I'm working on a project where I would like to run a simple web front end
>for it. To save the time of implementing my own HTTP server I'd like to
>embed Tomcat. I've read several documents on how to do this, and I've
>managed to get Tomcat running inside my program. However, all the examples
>I've seen show how to load a WAR file and use that as a web application. If
>it's possible, I'd rather just have a sevlet class inside my program that
>Tomcat uses rather than having an external web application.
>
You should be able to get away with just a single external file: a
web.xml file that mounts the servlet and maps it to a URI pattern. The
rest of the webapp code (ie the servlet class you mentioned) would be
able to be inside the main jar, because class loader inheritance would
cause the servlet class to be visible even if it's not in the
WEB-INF/classes folder.

If one external file is too many, you might need to do something tricky
to set the webapp's mounted instances from code. Maybe via JMX ? Someone
else might be able to help here ....

Rick

--
Servlet v2.4 container in a single 155KB jar file ? Try Winstone (http://winstone.sourceforge.net/)



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org