Hi Jan

What I am trying to achieve is to easily start building new applications
with embedded Jetty without having to use external programs (like
jetty-runner), XML files (like context XML) or frameworks (like
DropWizard). I can copy and paste this main class, but I would rather avoid
the magic parts so it doesn't require special knowledge (especially the
trick with setting the init parameter).

I am indeed running on Windows (is that the only platform that supports
fileMappedBuffers)? Setting the init-parameter like this actually does work
(I use it every day) and requires less code than what's needed to have a
custom context XML. But like I said: It's undocumented and a bit magic.

I am still trying to figure out what change I would like to see in Jetty
for this.

I agree that in this case, the src/main/resources/webapp path is specific
to the way this application is packaged and something that makes sense to
configure.

I guess that ideally for me would be if the default value of
fileMappedBuffers would depend on whether the value in setWar is a
directory or a JAR file. Does this distinction make sense to you?


~Johannes


On Fri, Jan 2, 2015 at 6:04 PM, Jan Bartel <[email protected]> wrote:

> Hi Johannes,
>
> Have you considered using the jetty-runner? Here's the doc:
> http://www.eclipse.org/jetty/documentation/current/runner.html#jetty-runner
>
> You could point it at your src/main/resources/webapp dir as the webapp
> to deploy. However, as it seems you're running on windows, you'll need
> to use a context xml file instead to set the context param to turn off
> fileMappedBuffers, and to point to your webapp and context path.
>
> OTOH, your main is a pretty simple class ... it could be made more
> generic by using system properties to set the context path, webapp to
> deploy and the fileMappedBuffers property.
>
> cheers
> Jan
>
> On 2 January 2015 at 16:15, Johannes Brodwall <[email protected]>
> wrote:
> > Hi
> >
> > I would like to hear if someone could suggest how to scratch this itch I
> > often have when using Jetty embedded in applications.
> >
> > I am often using Jetty during development. I'd like for static files that
> > are normally packaged into a war or jar file to be easy to edit when I am
> > developing (that is, when the files are not packaged). At the same time,
> I
> > want my code to be as similar as possible during development and in
> > production.
> >
> > My best attempt so far has been to place the static content under
> > src/main/resources/webapp and package it into the Jar-file.
> >
> > In order to avoid locking the files when I'm running the server in the
> > debugger, I've implemented the following:
> >
> >     public static WebAppContext createApplicationContext() {
> >         WebAppContext webapp = new WebAppContext("/webapp", "/app");
> >
> >         if
> >
> (SimpleServer.class.getResource(webapp.getWar()).getProtocol().equals("file"))
> > {
> >             // Avoid locking static content when running exploded
> >             webapp.setWar("src/main/resources/webapp");
> >
> >
> webapp.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer",
> > "false");
> >         }
> >         return webapp;
> >     }
> >
> > This runs in a main method like so:
> >
> > public class SimpleServer {
> >
> >     public static void main(String[] args) throws Exception {
> >         HandlerList handlers = new HandlerList();
> >         handlers.addHandler(new ShutdownHandler("randomtoken", false,
> > true));
> >         handlers.addHandler(createApplicationContext());
> >
> >         Server server = new Server(5000);
> >         server.setHandler(handlers);
> >         server.start();
> >
> >         System.out.println("Started " + server.getURI());
> >     }
> > }
> >
> > As the rest of the code is extremely simple, the magic replacement of the
> > target file with the source file and the setting of the very poorly
> > documented "org.eclipse.jetty.servlet.Default.useFileMappedBuffer"
> parameter
> > both feel really frustrating. The code is magic enough that I've ended up
> > creating a "framework" to run it which is clearly not what I want.
> >
> >
> > 1. Are there currently better ways of doing this?
> > 2. Is there any way something that accomplishes the same could be added
> to
> > Jetty itself?
> >
> >
> > ~Johannes
> >
> >
> >
> > _______________________________________________
> > 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
>
>
>
> --
> Jan Bartel <[email protected]>
> www.webtide.com
> 'Expert Jetty/CometD developer,production,operations advice'
> _______________________________________________
> 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

Reply via email to