Hi Christian I ran into the same problem as you and was able to solve it. :-)
If you look at the source related to AnnotationConfiguration.scanForAnnotations this looks through getWebInfClassesDirs and getOrderedWebInfJars, which doesn't work for those of us who don't have a WAR file. What I ended up doing was to scan my classpath myself! This entailed: 1. Create a AnnotationParser annotationParser = new AnnotationParser(); 2. Iterating over ((URLClassLoader) getClass().getClassLoader()).getURLs() 3. Calling annotationParser.parse for each classpath entry I had to create my own ClassNameResolver to support my classpath. Here's a Gist that ought to help you out: https://gist.github.com/jhannes/e795c1828a203fc82d33 ~Johannes On Fri, Jan 16, 2015 at 3:26 PM, Christian Reuschling < [email protected]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > > we have no war file, nor some extra classpath, but simply want to add our > servlet object instance > to the embedded server, by taking it's servlet 3.0 parameters into account. > > All the documentation on Jetty, and all examples and snippets we found for > embedded + servlet 3.0 > annotations deals with specifying a war file or a classpath, which will be > scanned by > AnnotationConfiguration then. > > We tried a lot, but we were not able to do the same by simply adding the > servlet with > context.addServlet(). > > Here is our code: > > > Server server = new Server(iPort); > > // tried: ServletHandler handler = new ServletHandler(); > // tried: WebAppContext contextHandler = new WebAppContext(); > ServletContextHandler contextHandler = new ServletContextHandler(); > contextHandler.setContextPath("/"); > > // tried: contextHandler.setConfigurations(new Configuration[] { > // new AnnotationConfiguration() }); > // tried: contextHandler.setConfigurationDiscovered(true); > > contextHandler.addServlet(new ServletHolder(new ExampleServlet()), > "/*"); > server.setHandler(contextHandler); > > server.start(); > > > The Servlet is a simple HttpServlet with following annotations: > > @WebServlet(urlPatterns = { "/example/*" }, loadOnStartup = 1, initParams = > { > @WebInitParam(name = "name1", value = "val1"), > @WebInitParam(name = "name2", value = "val2") > }) > @MultipartConfig(fileSizeThreshold = 1024*1024*10) > public class ExampleServlet extends HttpServlet > {....} > > > > How is it possible that the embedded Jetty server simply takes the > annotations of the Servlet > Object added to the server with context/handler.addServlet(..) into > account, and nothing else, as > the most simple scenario. > > > Thanks for all answers! > > Christian > > > > - -- > > ______________________________________________________________________________ > Christian Reuschling, Dipl.-Ing.(BA) > Software Engineer > > Knowledge Management Department > German Research Center for Artificial Intelligence DFKI GmbH > Trippstadter Straße 122, D-67663 Kaiserslautern, Germany > > Phone: +49.631.20575-1250 > mailto:[email protected] http://www.dfki.uni-kl.de/~reuschling/ > > - ------------Legal Company Information Required by German > Law------------------ > Geschäftsführung: Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster (Vorsitzender) > Dr. Walter Olthoff > Vorsitzender des Aufsichtsrats: Prof. Dr. h.c. Hans A. Aukes > Amtsgericht Kaiserslautern, HRB 2313= > > ______________________________________________________________________________ > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.19 (GNU/Linux) > > iEYEARECAAYFAlS5H6cACgkQ6EqMXq+WZg/P3wCfY8Fjvk+KTgFsh13QG/FvVaH+ > lkMAnjIgWeu07XYxaee56wKMNOszdglP > =g7VS > -----END PGP SIGNATURE----- > _______________________________________________ > jetty-users mailing list > [email protected] > To change your delivery options, retrieve your password, or unsubscribe > from this list, visit > https://dev.eclipse.org/mailman/listinfo/jetty-users >
_______________________________________________ jetty-users mailing list [email protected] To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/jetty-users
