Monday 15 February 2010

java - Embedding Jetty as a Servlet Container -


I am using tomcakes to serve my Java Servlets and this is just a bit more for me I just need the service Is servicelet requests alone, no static content, no JSP etc. So I was looking for a sublet container which can be embedded in my application. I felt that if Jetties are stripped and used alone as a service container, then it can be more scalable and capture small memory footprint [me] Jetti's 'web server' and others Parts are not required] So I have some questions, though

  1. How do I embed Jetty in my application code to serve only Servlet requests?
  2. If I embed the code in my application code, will I be able to easily upgrade the JT versions?
  3. I have got a JET code, if I have to embed Jettie's serlet container in my app, then I should use it from source, JT-9.0 .3.v20130506 / JetT-servlet or JT-9.0 .3.v20130506 / JT-Serlet

    I intend to complete API requests with my applications and I am looking for performance and scalability, main constraints and of course servlet 3.0 support.

    What you are seeing is running Jettie in an embedded scenario.

    For the record, for Jetti standalone

    How can you show the various pieces needed to meet your goals together? Actually, just a few startups and Jetpath embedded with Bootstrap related to Classpath. This is the same code, and originally assembled in the same way.

    Since you said that you want sublet 3.0, there is no interest in JSP, it is not easy to setup (JSP is easy to setup but possible).

    Servlet 3.0 is a complete example project hosted on Gitub, for specific embedding.

    In short, you will have the following initial code.

      package com.company.foo; Import org.eclipse.jetty.annotations.AnnotationConfiguration; Import org.eclipse.jetty.plus.webapp.EnvConfiguration; Import org.eclipse.jetty.plus.webapp.Plus configuration; Import org.eclipse.jetty.server.Server; Import org.eclipse.jetty.webapp.configuration; Import org.eclipse.jetty.webapp.FragmentConfiguration; Import org.eclipse.jetty.webapp.MetaInfConfiguration; Import org.eclipse.jetty.webapp.TagLibConfiguration; Import org.eclipse.jetty.webapp.WebAppContext; Import org.eclipse.jetty.webapp.WebInfConfiguration; Import org.eclipse.jetty.webapp.WebXmlConfiguration; Public category embedme {public static zero main (string [] args throws exception {int port = 8080; Server server = new server (port); String warder = "target / sample-webpage-1-snapshot"; WebAppContext Reference = New WebAppContext (); // This could be a jar file of your own project, but the content should be consistent with / // wise layout. Context.setResourceBase (wardir); // A Web-INF / Web Xml requires servlet 3.0 context.setDescriptor (wardir + "WEB-INF / web.xml"); // Auto-wire up / circlet 3.0 annotations, descriptors, and pieces references. Set configuration (new configuration [] (new annotation configuration), new webaxal configuration (), new webinf configuration (), new tag lib configuration), new plus configuration (), new metafind configuration (), new fragment configuration (), new And configuration ()}); // Specify the reference path, which you want the webpage to appear as reference .setContextPath ("/"); // To use the "server" squared on the webapp square path, tell the classloader (This is because jar and lbs are used in your // server class, for which no WEB-INF / lib / directory exists Is) context.setParentLoaderPriority (true); // Add this webpad to the server server.Setroller (reference); // Start server thread server. Start (); // Wait for server thread to stop (optional) server.join (); }}    

No comments:

Post a Comment