Since you are doing embedded work, you might want to take a look at our embedded jetty examples. https://github.com/eclipse/jetty.project/tree/master/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded
Of particular interest might be FileServer.java Which uses ResourceHandler to serve files. http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/server/handler/ResourceHandler.html Incidentally, we serve javadoc in the distribution with ResourceHandler -- ${jetty.home}/contexts/javadoc.xml https://github.com/eclipse/jetty.project/blob/master/jetty-distribution/src/main/resources/contexts/javadoc.xml Also note that the WebAppContext.setDefaultsDescriptor() is how you can configure to use the default servlet from a WebAppContext. http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setDefaultsDescriptor(java.lang.String) For an example of this usage, see the distribution again -- ${jetty.home}/contexts/test.xml https://github.com/eclipse/jetty.project/blob/master/test-jetty-webapp/src/main/config/contexts/test.xml -- Joakim Erdfelt <[email protected]> www.webtide.com Developer advice, services and support from the Jetty & CometD experts. On Fri, Sep 21, 2012 at 7:22 AM, Olek Swirski <[email protected]> wrote: > Hi, > I'm using embedded jetty instance to serve my Lift application (Scala > based web framework). > I use a runnable Start object with main method, which configures embedded > jetty and starts > the server. So the jar is executed like so: java -jar my-webapp.jar > My application uses a directory, where images are stored. It can grow > quite big and because > of that I don't want to include it and deploy together with my runnable > jar. So the ideal > thing to do for me is to use a symlink to some external dir holding these > pictures. However, > I have problem setting this up. When I was using standalone jetty entry > like this: > <servlet> > <servlet-name>default</**servlet-name> > <servlet-class>org.eclipse.**jetty.servlet.DefaultServlet</** > servlet-class> > <init-param> > <param-name>aliases</param-**name> > <param-value>true</param-**value> > </init-param> > </servlet> > > in etc/webdefault.xml was working fine. But in my embedded jetty i'm not > using xml file config. Instead my setup is done in the main method of > executable > class, that runs the jar (please take a look below the messag to see the > code - > (it's in Scala but should be very easy to understand for java devs). So, > the thing is > I tried: > webctx.setAttribute("aliases", "true") > and also: > webctx.setInitParameter("**aliases", "true") > but then, when restarted jetty, nothing really changed, and aliases / > symlinks > were not traversed by jetty. Instead I got 404s. > I was trying to set up a separate handler, and call .setAliases(true) on > it, but > then when I did: > server.setHandler(webctx) > server.setHandler(**aliasedHandler) > server.start > server.join > the app wouldn't work even for non-aliased files. I understand, probably > this > was because of both handlers overlapping. But I'm not very experienced with > jetty, so please let me know, how to make it work. So what should I do to > have > it work same way as with xml based > <param-name>aliases</param-**name> > <param-value>true</param-**value> ? > > I did search for quite long time to find an answer for this, but didn't > find > anything that actually worked. Please share your knowledge on this subject, > any hint will be greatly appreciated :) Here is my current Scala code > which unfortunately doesn't work with aliases / symlinks: > > val port = portFromCommandLine.getOrElse(**Props.getInt("jetty.emb.port", > 9090)) > println("USING PORT: " + port) > val server = new Server(port) > val webctx = new WebAppContext > /* use embedded webapp dir as source of the web content > * web.xml is in default location, of embedded webapp dir, > * so don't need to adjust that */ > val webappDirInsideJar = webctx.getClass.** > getClassLoader.getResource("**webapp").toExternalForm > webctx.setWar(**webappDirInsideJar) > /* might use use external pre-existing webapp dir instead of > referencing > * the embedded webapp dir but it's not very useful. why would we put > * webapp inside jar if we end up using some other external webapp dir. > * I put it for reference, as it may make sense under some > circumstances. > * webctx.setResourceBase("/path/**to/existing/webapp-dir") */ > webctx.setContextPath("/") > webctx.setAttribute("aliases", "true") > > /* optionally extract embedded webapp to specific temporary location > and serve > * from there. In fact /tmp is not a good place, because it gets > cleaned up from > * time to time so you need to specify some location such as /var/www/ > sqrlrcrd.com > * for anything that should last */ > val shouldExtract = Props.getBool("jetty.emb.**extract", false) > if (shouldExtract) { > val webtmpdir = Props.get("jetty.emb.tmpdir", "/tmp") > webctx.setTempDirectory(new File(webtmpdir)) > } > > server.setHandler(webctx) > server.start > server.join > > Here is this file at github, just I didn't put alias-enabling code there, > because > couldn't make it work so far: https://github.com/oolekk/** > sqrlrcrd.com/blob/master/src/**main/scala/bootstrap/liftweb/**Start.scala<https://github.com/oolekk/sqrlrcrd.com/blob/master/src/main/scala/bootstrap/liftweb/Start.scala> > > Also here is a thread on Lift mailing list, about packaging jetty 8 > together with > lift web application to create runnable, self serving jar: > https://groups.google.com/**forum/?fromgroups=#!topic/** > liftweb/uwwIA8FwmU8<https://groups.google.com/forum/?fromgroups=#!topic/liftweb/uwwIA8FwmU8> > > Thank you in advance for your help. > > ______________________________**_________________ > jetty-users mailing list > [email protected] > https://dev.eclipse.org/**mailman/listinfo/jetty-users<https://dev.eclipse.org/mailman/listinfo/jetty-users> >
_______________________________________________ jetty-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/jetty-users
