What is minimal configuration for embedded Jetty?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

What is minimal configuration for embedded Jetty?

Stepan RYBAR
Hello!

I want to use Jetty as embeded HTTP/Java servlet server (together with HSQLDB and my Java servlet code). Default installation of Jetty is quite large for such purpose (about 6.43 MB). Is there any document saying, which parts of Jetty can be used for such purpose? I think somethink like list of directories, jars, config files and start, stop file.

I tried to find this information via Google and this mailing list archive, but I was unsuccessfull.

Thank You in advance for the answer.

Stepan

____________________________________________________________
http://www.listicka.cz


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: What is minimal configuration for embedded Jetty?

Anthony Cook
Greetings,

A "minimal" configuration for Jetty depends on what you really want it for.

To use Jetty as an embedded server -- that is, enclosing it within your
application, rather than using it to serve your application -- requires
at a minimum the following jars from the base Jetty distribution
(relative to $JETTY_HOME): lib/org.mortbay.jetty.jar,
lib/javax.servlet.jar, and ext/commons-logging.jar.  The code below is
an illustrative example of this and serves as a simple file system
viewer with Jetty's Dump servlet also being provided.  Including the
requisite jars, the total size of the application is a little under 800K
only (based on Jetty 5.1.4 dist).

Ultimately, to use Jetty as a stand-alone server which does the same
thing, but is otherwise not "embedded" in the application itself,
requires little more... needing just the addition of a "jetty.xml"
configuration file to configure the server in similar fashion as is done
in the MyJettyFSViewer class.  More information is found in the Jetty
Tutorial sections, "Getting Started" and "The Basics".  These provide
"dive in" introductions to starting and configuring Jetty, respectively.

[MyJettyFSViewer.java; shamelessly based on the example provided in the
Jetty tutorial. :) ]
x-------------- >8 --------------x
import org.mortbay.http.HttpContext;
import org.mortbay.http.HttpServer;
import org.mortbay.http.SocketListener;
import org.mortbay.http.handler.ResourceHandler;
import org.mortbay.jetty.servlet.ServletHandler;

public class MyJettyFSViewer
{
    public static void main( String[] args )
      throws Exception
      {
         if( args.length != 2 )
           {
              System.err.println( "Usage: java -cp <CLASSPATH>
MyJettyFSViewer <port> <path>" );
              System.err.println( "  CLASSPATH must include the
following JAR files:" );
              System.err.println( "    org.mortbay.jetty.jar" );
              System.err.println( "    javax.servlet.jar" );
              System.err.println( "    commons-logging.jar" );
              System.exit( 5 );
           }

         int port = Integer.parseInt( args[0] );
         String contextPath = args[1];

         // Create the server
         HttpServer server = new HttpServer();

         // Create a port listener
         SocketListener listener = new SocketListener();
         listener.setPort( port );
         server.addListener( listener );

         // Create a context
         HttpContext context = new HttpContext();
         context.setContextPath( "/myfs/*");
         server.addContext(context);

         // Create a servlet container
         ServletHandler servlets = new ServletHandler();
         context.addHandler( servlets );

         // Map a servlet onto the container
         servlets.addServlet( "Dump", "/Dump/*",
"org.mortbay.servlet.Dump" );

         // Serve static content from the context
         context.setResourceBase( contextPath );
         context.addHandler( new ResourceHandler() );

         // Start the http server
         server.start ();
      }
}
x-------------- 8< --------------x

Regards,

Anthony Cook


Stepan RYBAR wrote:

> Hello!
>
> I want to use Jetty as embeded HTTP/Java servlet server (together with HSQLDB and my Java servlet code). Default installation of Jetty is quite large for such purpose (about 6.43 MB). Is there any document saying, which parts of Jetty can be used for such purpose? I think somethink like list of directories, jars, config files and start, stop file.
>
> I tried to find this information via Google and this mailing list archive, but I was unsuccessfull.
>
> Thank You in advance for the answer.
>
> Stepan
>
> ____________________________________________________________
> http://www.listicka.cz
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support


vschade.vcf (226 bytes) Download Attachment