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,

On 22 January 2015 at 11:02, Johannes Brodwall <johannes@xxxxxxxxxxxx> wrote:
>
> On Fri, Jan 16, 2015 at 12:39 PM, Jan Bartel <janb@xxxxxxxxxxx> wrote:
>>
>>
>> >
>> > Actually, you're right - there are enough ways. The approach that I am
>> > using
>> > is the same as the one from the Heroku sample application. It is also
>> > the
>> > way described under "Setting a Web Application Context" under
>> > https://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty. I personally
>> > thing
>> > these are the best ways of using Jetty.
>>
>> You are referring to old doco, the eclipse wiki is no longer the
>> canonical repository for jetty documentation. You should look at:
>> http://www.eclipse.org/jetty/documentation/. If you're looking at the
>> old wiki because you're using jetty-7 or jetty-8, then  they're
>> end-of-life, and the best way forward is to upgrade to jetty-9 ;)
>>
>
> I'm am luckily using Jetty 9. :-)

Excellent! :)

> But the corresponding page in the new
> documentation doesn't seem to cover this as well. The scenario of the
> exploded webapp is missing at
> https://www.eclipse.org/jetty/documentation/current/embedding-jetty.html
>
> To be honest, I think that the old documentation with the simple
> non-commented code examples is more encouraging than the new with lots of
> embedded comments.

That's a bit disappointing considering the effort we've gone to to
improve the doco :(  Maybe might be a good idea to make a contribution
to the doco to put in the info that you really want to see:

  https://github.com/jetty-project/jetty-documentation

[snip]

> Again, I'm mainly concerned about teachability. I have several times had
> people express "wow, this was really easy to get started with" and then a
> few hours laters start swearing about the locked files, only to throw Jetty
> away in disgust.
>
> To be honest, I think that you got the useFileMappedBuffer wrong. Perhaps
> the default should have been false? Perhaps the default should have been
> false if the resource was in the classpath?

Mmmn, well as we discussed, it is false in the code, and overridden to
be true by the webdefault.xml (which is of course replaceable). The
thing is, having it set to "true" is the right thing to do in both of
the following circumstances: 1. when running in production, 2. when
running on *nix. Now, most production servers are *nix machines, so
the setting makes a lot of sense. The only combination that is
problematic is Windows in development.

In the past, we've had this set around the other way, and we got
yelled at by all the *nix users because performance was worse. Now its
back to true, we get yelled at by the Windows users :).  We figure
that either one community or the other is going to have to change the
setting to suit, which is why we give you a number of different ways
to change it.

Perhaps this can be resolved simply by more (obvious) warnings in the
documentation?

Jan
>
>
> ~Johannes
>
>
>>
>> >
>> >
>> > ~Johannes
>> >
>> >>
>> >> > On Fri, Jan 2, 2015 at 6:04 PM, Jan Bartel <janb@xxxxxxxxxxx> 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
>> >> >> <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
>> >> >> > https://dev.eclipse.org/mailman/listinfo/jetty-users
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Jan Bartel <janb@xxxxxxxxxxx>
>> >> >> www.webtide.com
>> >> >> 'Expert Jetty/CometD developer,production,operations advice'
>> >> >> _______________________________________________
>> >> >> jetty-users mailing list
>> >> >> jetty-users@xxxxxxxxxxx
>> >> >> 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
>> >> > jetty-users@xxxxxxxxxxx
>> >> > To change your delivery options, retrieve your password, or
>> >> > unsubscribe
>> >> > from
>> >> > this list, visit
>> >> > https://dev.eclipse.org/mailman/listinfo/jetty-users
>> >>
>> >>
>> >>
>> >> --
>> >> Jan Bartel <janb@xxxxxxxxxxx>
>> >> www.webtide.com
>> >> 'Expert Jetty/CometD developer,production,operations advice'
>> >> _______________________________________________
>> >> jetty-users mailing list
>> >> jetty-users@xxxxxxxxxxx
>> >> 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
>> > jetty-users@xxxxxxxxxxx
>> > To change your delivery options, retrieve your password, or unsubscribe
>> > from
>> > this list, visit
>> > https://dev.eclipse.org/mailman/listinfo/jetty-users
>>
>>
>>
>> --
>> Jan Bartel <janb@xxxxxxxxxxx>
>> www.webtide.com
>> 'Expert Jetty/CometD developer,production,operations advice'
>> _______________________________________________
>> jetty-users mailing list
>> jetty-users@xxxxxxxxxxx
>> 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
> jetty-users@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users



-- 
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
'Expert Jetty/CometD developer,production,operations advice'


Back to the top