Search code examples
mavenjetty

Hot deployment failure with Maven jetty plugin on Windows


I have configured the Jetty Maven plugin to run my compiled war.

Here is the relevant part of my pom.xml.

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.4.50.v20221201</version>
    <configuration>
      <war>${jway.webapps.dir}/myapp.war</war>
      <scanIntervalSeconds>2</scanIntervalSeconds>
    </configuration>
</plugin>

If I execute mvn jetty:run-war, my war is build and Jetty serves the app as expected.

I have configured scanIntervalSeconds to allow hot redeploy. However, if I rebuild using mvn install, I get the following error during redeployment:

java.lang.IllegalStateException: Failed to delete temp dir F:\...\myproject\target\tmp
    at org.eclipse.jetty.webapp.WebInfConfiguration.configureTempDirectory (WebInfConfiguration.java:532)
    at org.eclipse.jetty.webapp.WebInfConfiguration.resolveTempDirectory (WebInfConfiguration.java:424)
    at org.eclipse.jetty.webapp.WebInfConfiguration.preConfigure (WebInfConfiguration.java:140)
    at org.eclipse.jetty.webapp.WebAppContext.preConfigure (WebAppContext.java:488)
    at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:523)
    at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart (JettyWebAppContext.java:397)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:73)
    at org.eclipse.jetty.maven.plugin.JettyRunWarMojo.restartWebApp (JettyRunWarMojo.java:113)
    at org.eclipse.jetty.maven.plugin.AbstractJettyMojo$1.filesChanged (AbstractJettyMojo.java:472)
    at org.eclipse.jetty.util.Scanner.reportBulkChanges (Scanner.java:848)
    at org.eclipse.jetty.util.Scanner.reportDifferences (Scanner.java:765)
    at org.eclipse.jetty.util.Scanner.scan (Scanner.java:641)
    at org.eclipse.jetty.util.Scanner$1.run (Scanner.java:558)
    at java.util.TimerThread.mainLoop (Timer.java:555)
    at java.util.TimerThread.run (Timer.java:505)

It seems that Jetty wants to delete the file, but Windows locks the file. In the plugin documentation, I have not found any configuration which seems to be helpful. Furthermore I have nothing found on Google. Is there any way to solve this issue?

I don't know if its relevant, but I do not use the jetty:run goal, because my war is build using a third party tool and I do not have a standard directory structure.


Solution

  • The jetty documentation contains a section about Troubleshooting Locked Files on Windows.

    So I updated my plugin config according to the documentation:

    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.4.50.v20221201</version>
      <configuration>
        <war>${jway.webapps.dir}/myapp.war</war>
        <scanIntervalSeconds>2</scanIntervalSeconds>
        <webApp>
        <_initParams>
            <org.eclipse.jetty.servlet.Default.useFileMappedBuffer>false</org.eclipse.jetty.servlet.Default.useFileMappedBuffer>
        </_initParams>
        </webApp>
      </configuration>
    </plugin>