Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Avoiding file-locking when developing with embedded Jetty

Hi Johannes,

Have you considered using the jetty-runner? Here's the doc:

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.


On 2 January 2015 at 16:15, Johannes Brodwall <johannes@xxxxxxxxxxxx> 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
> jetty-users@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit

Jan Bartel <janb@xxxxxxxxxxx>
'Expert Jetty/CometD developer,production,operations advice'

Back to the top