Jetty Maven Plugin is ignoring custom webdefault.xml

人走茶凉 提交于 2019-12-17 18:52:23

问题


I'm trying to get around the common issue of Jetty locking static files on Windows with the technique of setting useFileMappedBuffer to false in webdefault.xml. Unfortunately, every time Jetty is not picking up my customized webdefault.xml.

I'm using Apache Maven 3.0.2. I've tried using the maven-jetty-plugin (v6.1.26) and jetty-maven-plugin (v8.0.0.M2) but with no difference. I've tried running clean and rebuilding as well before running Jetty.

I've verified each time that my webdefault.xml was taken from the same version as the plugin and has the correct settings, namely, only changing this setting from true to false:

...
<init-param>
  <param-name>useFileMappedBuffer</param-name>
  <param-value>false</param-value>
</init-param>
...

And here's what my pom.xml Jetty plugin section looks like:

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <configuration>
        <contextPath>/</contextPath>
        <webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
    </configuration>
</plugin>

I've also tried altering the path to my file:

<webDefaultXml>${basedir}/src/main/resources/webdefault.xml</webDefaultXml>

Everywhere I've seen this exact solution and it sounds like it is working for others (although I found one instance where someone had my issue). The startup for jetty has this in the output:

> mvn jetty:run
...
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
...

This further makes me think it isn't being applied. All the other paths are correct in the output.

My most direct issue that I'm seeing while Jetty is running is that whenever I edit a static file (JavaScript, CSS, etc.) with IntelliJ IDEA 10, I get this error message:

Cannot save file:
D:\...\... (The requested operation cannot be performed on a file with a user-mapped section open)

After I stop Jetty then it saves just fine. This happens every time.

Any ideas what I could be doing wrong? Thanks in advance.


回答1:


I found an entirely different doc for the newer Jetty plugin jetty-maven-plugin (v8.0.0.M2) and it looks like the configuration name has changed:

http://wiki.eclipse.org/Jetty/Reference/webdefault.xml#Using_the_Jetty_Maven_Plugin

<project>
    ...
    <plugins>
        <plugin>
            ...
            <artifactId>jetty-maven-plugin</artifactId>
            <configuration>
                <webAppConfig>
                  ...
                  <defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor>
                </webAppConfig>
            </configuration>
        </plugin>
        ...
    </plugins>
    ...
</project>

This now seems to work for the newer plugin. I'm still unsure why the v6 plugin does not pick up the customized config.




回答2:


The only solution I found that worked with maven-jetty-plugin 6.1.24 was this: http://false.ekta.is/2010/12/jettyrun-maven-plugin-file-locking-on-windows-a-better-way/




回答3:


The Jetty documentation outlines three ways to do it (as of Jetty 9):

https://www.eclipse.org/jetty/documentation/current/troubleshooting-locked-files-on-windows.html

I successfully used the init-param method in Maven:

        <!-- Running an embedded server for testing/development -->
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.4.9.v20180320</version>

            <configuration>
                <webApp>
                    <_initParams>
                        <org.eclipse.jetty.servlet.Default.useFileMappedBuffer>false</org.eclipse.jetty.servlet.Default.useFileMappedBuffer>
                    </_initParams>
                </webApp>
            </configuration>

        </plugin>


来源:https://stackoverflow.com/questions/4988019/jetty-maven-plugin-is-ignoring-custom-webdefault-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!