Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Jetty plugin locking files

Tags:

gradle

jetty

Is there a way to fix the file locking issue caused by jetty entirely from gradle?

Some clarification:
When using the Gradle Jetty plugin by running gradle jettyRun, jetty causes the static resource files (html, css, js, etc.) to be locked when using Windows. You can see a description of the problem in Files locked on Windows.

The same article also describes how you can fix that. Basically you have to either:

  1. Disable the use of file mapped buffer
  2. Not use NIO at all.

Both things require to add some jetty specific configuration files to the project, which I do not want to do - the jetty plugin is used only for convenience, and maintaining configuration for it does not feel right.

I do not need NIO for testing on the local machine, so any solution works.

Edit:

For now, I picked the option at which you set useFileMappedBuffer to false. This is how to do it:

  1. Specify a path to your webdefault.xml like

    [jettyRun, jettyRunWar,jettyStop]*.with {
        //other configs
    
        webDefaultXml = file("${project.webAppDir}/WEB-INF/jetty-webdefault.xml")
    }
    
  2. Get file from the latest 6.1.x distribution of jetty. The plugin seems to support only jetty 6. You can localte it at jetty-6.1.26\etc\webdefault.xml. Obviously, you have to place it at the path specified at the previous step.

  3. Change the default servlet init parameter useFileMappedBuffer to false

I will research the option of using embeded jetty insted of the plugin.

like image 756
jmruc Avatar asked Jun 14 '12 11:06

jmruc


2 Answers

I found a plugin that seem to be a better alternative:

https://github.com/akhikhl/gretty

Positives

  • Does not lock your files and support hot deployment (even something Gretty call "fast reload")
  • Gretty 1.2.0 uses Jetty 9.2.9.v20150224. Jetty plugin provided by Gradle 2.2.1 uses Jetty 6.1.25.
  • same task is used jettyRun (or more simply run).
  • "Press any key to stop the server". Jetty plugin required CTRL+C then Y.
  • From what I can tell, the documentation seem to be awesome (Gradle's not so much)

Negatives

  • A bit more bloated code to setup the buildscript's classpath dependency or apply plugin directly from URL (see doc)
  • Gretty crash unless you explicitly apply plugin: 'war' (Jetty plugin extends the War plugin)
like image 175
Martin Andersson Avatar answered Nov 03 '22 21:11

Martin Andersson


Kiril answered his own question, many thanks. You should follow Kiril's instructions and this will help you find the appropriate webdefault.xml.

To find out what version of Jetty is started by Gradle, execute

gradle jettyRun -i

And you'll see something like this:

...
Tmp directory =  determined at runtime
Web defaults = org/mortbay/jetty/webapp/webdefault.xml
Web overrides =  none
Webapp directory = C:\dev\my-project\src\main\webapp
Starting jetty 6.1.25 ...
jetty-6.1.25
...

It took me a while to find a copy of Jetty 6.1.25 as it is no longer listed on the Jetty download page (not even in the archive section!).

You can then grab the appropriate copy of webdefault.xml from here, adjusting the version number as appropriate for your needs:

http://grepcode.com/file/repo1.maven.org/maven2/org.mortbay.jetty/jetty/6.1.25/org/mortbay/jetty/webapp/webdefault.xml

like image 22
vegemite4me Avatar answered Nov 03 '22 20:11

vegemite4me