jetty:run maven plugin file locking on windows, a better way

If you use something like jetty:run while developing webapps on windows, sooner or later you’ll run into a problem with file locking. Any editor worth using normally lets you edit jsp files, css or js files and have the changes immediately be visible, without having to start/stop the servlet container, or (heaven forbid) rebuild the .war.

Jsp files don’t seem to be affected, because they have to be recompiled, but editing js and css files, say in a resources directory, fail.
Jetty has an extensive reference on this and if you search the web you’ll find hundreds of people parroting this in one form or another.

In my opinion, it’s a terrible solution. I most certainly do _NOT_ want to have to copy a jetty webdefault.xml file into my project, and maintain any changes made in the plugin upstream. I do _NOT_ want to have to hardcode a path to a local jetty install. I DO use more than one servlet container, and have no desire to include jetty specific garbage in my main web.xml file. But all this talk of changing the value of useFileMappedBuffer can be avoided completely.

Step back a bit, the problem is caused by NIO on windows. If you’re running jetty for embedded development purposes via jetty:run, do you really give a shit about the performance difference with hundreds of threads vs traditional blocking IO? No. Not in the least. So instead of hacking and poking jetty files, just change the plugin config to not use NIO. Like so…..

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.18</version>
    <configuration>
        <contextPath>${project.parent.artifactId}</contextPath>
        <connectors>
            <!-- work around file locking on windows -->
            <connector implementation="org.mortbay.jetty.bio.SocketConnector">
                <port>8080</port><!-- this connector defaults to 1300 for some reason -->
            </connector>
        </connectors>
    </configuration>
</plugin>
Leave a comment ?

10 Comments.

  1. Hi,

    Nice find, just had the same problem when making a project that has local development on jetty and live deployment on glassfish. Tried to do it in the jetty-web.xml but this is way easier.

    ps for the ‘new’ eclipse one use
    org.eclipse.jetty.server.bio.SocketConnector

    grtz

  2. Thanks a lot to both KarlP and Bram, this solved my problem.

  3. Much better solution for development purposes.

  4. Nice solution. I wrote a blog entry to introduce this way to Japanese readers.

  5. Really neat solution !!!

    If you want to make it work with newer version of jetty (starting from v7) :

    org.mortbay.jetty
    jetty-maven-plugin
    8.1.9.v20130131

    ...

    8080

    ...

  6. Any idea how to make this work with Jetty 9? It appears the SocketConnector has been removed from that version.
    (*Chris*)

  7. Not a clue I’m afraid, I haven’t been working with java web apps for three and a half years or so now.

  8. works like a charm with org.eclipse.jetty.server.bio.SocketConnector on eclipse 4.3 and jetty 7.x, thanks

  9. As cybermopo already said the class name has changed in Jetty 7+ from
    org.mortbay.jetty.bio.SocketConnector
    to
    org.eclipse.jetty.server.bio.SocketConnector
    update if you have a ClassNotFoundException.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Trackbacks and Pingbacks: