Skip to main content

New Grizzly enhancement : Servlet AutoDeployer

Posted by survivant on April 1, 2009 at 7:43 PM PDT

We got something really cool for Grizzly. It's a Servlet AutoDeployer for GrizzlyWebServer.

Now that it said.. let's talk more about that.

When you have servlets, you will need a AppServer or a WebServer to deploy your applications. Nothing new there.. it's a been like that for years. Mostly you had to create a web.xml, put that in a war and deploy it.

There are others alternatives, like using GrizzlyWebServer, but you will have to put your web.xml into code.

GrizzlyWebServer ws = new GrizzlyWebServer(80);
try {
    ServletAdapter sa = new ServletAdapter();
    // need to load JspRuntimeContext
    Servlet servlet = (Servlet)ClassLoaderUtil.load("ca.sebastiendionne.welcome_jsp");
    ws.addGrizzlyAdapter(sa, new String[]{});
} catch (Exception e){
    s_logger.error("Error Launching GrizzlyWebServer",e);

What's wrong with that ?

In my point of view.. it's not efficient. I don't want to use a WebServer to deploy a simple servlet and I don't want code what I could simply extract from a config file.

That why a servlet autodeployer could be useful. Yes a WebServer or AppServer do that already, but like I said.. you can skip it and go for a smaller and faster solution.

The GrizzlyServletDeployer (or the super fast and super easy thing for GrizzlyWebServer) will do everything for you.

In one simple command line you can deploy multiple applications.

Let's take a look at the command line first.

java -jar grizzly-servlet-deployer-1.9.11-SNAPSHOT.jar [options]

where options are :

-p : the port [default 8080]
-a : applications to deploy (everything is done from that)

You can deploy many things from the option "-a" (servlets, war, multiple wars, expanded wars). Let's decribe what can be done.

Syntax examples :

# 1 : Deploy a war

java -jar grizzly-servlet-deployer-1.9.11-SNAPSHOT.jar -a c:/temp/hudson.war

That will deploy the war file. The same way a WebServer will deploy it. The web.xml will be read and the servlets will be deployed.

The context will be the war file. In this example : http://localhost:8080/hudson/

#2 - Deploy a expanded war.

java -jar grizzly-servlet-deployer-1.9.11-SNAPSHOT.jar -a c:/temp/hudson

Your application could be a expanded war, or have the same hierarchy.

That will give the same result as #1

#3 Deploy servlets

java -classpath myservlet.jar;.;grizzly-servlet-deployer-1.9.11-SNAPSHOT.jar com.sun.grizzly.http.servlet.deployer.GrizzlyWebServerDeployer -a web.xml

You can skip the step to create a war file if you want. Simply declare a web.xml and put the jars into the classpath (in this case the servlet is in myservlet.jar)

The context will be the default "/"


#4 - Deploy multiples war in the same time.

This one is more advanced. It will deploy all the war files or expanded wars that are in a root folder.

java -jar grizzly-servlet-deployer-1.9.11-SNAPSHOT.jar -a /MultipleWarFolder

(yes it's the same syntax as #2)

Example :

Here what the folders will look like


The folder /MultipleWarFolder contains 4 war files and 1 expanded folder.

Serlvet-Deployer will check all the folders in the root (/MultipleWarFolder) and check if it can apply #1 or #2.

If it find one that contains /WEB-INF/web.xml it will consider it as #2 (expanded war) and if it find a .war it will do #1 (war file).

The context for each application will be the folder name (freemarker) or the war file.

If you want to can use it in a testcase easily.

GrizzlyWebServerDeployer gws = new GrizzlyWebServerDeployer();

try {
    args = new String[]{"-a","./web.xml"};
    // ready to launch

    ... launch your tests...
} catch (Exception e){

I think when you will start using that, you will love it :)
This Servlet AudoDeployer support web.xml version 2.2 to 3.0

GrizzlyWebServer is really powerful and so small. It's a Asynchronous IO server that support multiples protocols : HTTP(s), Comet, PHP, JSP, Freemarker, AJP protocol (mod_jk) and more check (

Related Topics >>


thanks. Can you send your requests to ? We will be able to discuss about that and add the requested enhancements :) We can specify the port, we tough of adding a param to force the context name and classpath. You still can pass classpath using java --classpath ... but another param like that : -a hudson.war -classpath /lib/;/others_lib; .. I could easily use the Loader with any WebServer, but I don't see why yet. Jetty, Tomcat.. already load the web.xml (you don't have control on what they are doing.. but it's there)..

Is it possible to use a mixed approach?
I mean, use code to specify the port, context name, the web application directory, some extra classpath and then start/stop the server.
I'm using this approach with Jetty/Tomcat/Resin embedded and I found it quite useful.

In fact, I'm working on a project to be able to use different embedded containers, for testing purposes, and those are the common things many implement.
If I'm not mistaken, I could simply use the GrizzlyWebServerDeployer class passing the appropriate parameters, but I'm missing the option of having some extra classpath (not in WEB-INF/lib and not in the "launch classpath".

In any case, good job!

PD: For an example of what I mean, this is the code to use the Jetty implementation: S!

thanks Kostas for the feedback. Can you send your war file to the mailing-list : ? We will be able to debug it. can you try with the latest snapshot ? (we fix issues releated to http module) Or contact me at Twitter : @survivant

I have tried to deploy the axis web.xml, the same that is used for Tomcat. However, although I tried using either Maven or from command line using the snapshot jar and supplying classpath, I always get java.lang.ClassNotFoundException: org.apache.axis.transport.http.AxisServlet and some more but I think this is the main. Any ideas? Regards, Kostas