Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Jetty/Howto/Deal with Locked Windows Files"
(New page: {{Jetty Howto | introduction = (required) Jetty buffers static content for webapps such as html files, css files, images, etc. If you are using NIO connectors, Jetty uses memory-mapped fil...) |
m |
||
Line 1: | Line 1: | ||
{{Jetty Howto | {{Jetty Howto | ||
− | | introduction = | + | | introduction = |
− | Jetty buffers static content for webapps such as | + | Jetty buffers static content for webapps such as HTML files, CSS files, images, etc. If you are using NIO connectors, Jetty uses memory-mapped files to do this. The problem is that on Windows, memory mapping a file causes the file to lock, so that you cannot update or replace the file. Effectively this means that you have to stop Jetty to update a file. |
==Remedy== | ==Remedy== | ||
Line 7: | Line 7: | ||
Jetty provides a configuration switch in the <tt>webdefault.xml</tt> file for the <tt>DefaultServlet</tt> that enables or disables the use of memory-mapped files. If you are running on Windows and are having file-locking problems, you should set this switch to disable memory-mapped file buffers. | Jetty provides a configuration switch in the <tt>webdefault.xml</tt> file for the <tt>DefaultServlet</tt> that enables or disables the use of memory-mapped files. If you are running on Windows and are having file-locking problems, you should set this switch to disable memory-mapped file buffers. | ||
− | The default <tt>webdefault.xml</tt> file is | + | The default <tt>webdefault.xml</tt> file is in the <tt>lib/jetty.jar</tt> at <tt>org/eclipse/jetty/webapp/webdefault.xml</tt>. Extract it to a convenient disk location and edit it to change <tt>useFileMappedBuffer</tt> to <tt>false</tt>. |
<source lang="XML"> | <source lang="XML"> | ||
− | |||
− | <init-param | + | <init-param> |
− | <param-name | + | <param-name>useFileMappedBuffer</param-name> |
− | <param-value | + | <param-value>true</param-value> <!-- change to false --> |
− | </init-param | + | </init-param> |
</source> | </source> | ||
− | + | Make sure to apply your custom <tt>webdefault.xml</tt> file to all of your webapps. You can do that by changing the configuration of the [[Jetty/Feature/Deployment_Manager|Deployment Manager]] in <tt>etc/jetty.xml</tt>. | |
<source lang="XML"> | <source lang="XML"> | ||
− | |||
− | <Call name="addLifeCycle" | + | <Call name="addLifeCycle"> |
− | <Arg | + | <Arg> |
− | <New class="org.mortbay.jetty.deployer.WebAppDeployer" | + | <New class="org.mortbay.jetty.deployer.WebAppDeployer"> |
− | <Set name="contexts" | + | <Set name="contexts"><Ref id="Contexts"/></Set> |
− | <Set name="webAppDir" | + | <Set name="webAppDir"><SystemProperty name="jetty.home" default="."/>/webapps</Set> |
− | <Set name="parentLoaderPriority" | + | <Set name="parentLoaderPriority">false</Set> |
− | <Set name="extract" | + | <Set name="extract">true</Set>< |
− | <Set name="allowDuplicates" | + | <Set name="allowDuplicates">false</Set> |
− | <Set name="defaultsDescriptor" | + | <Set name="defaultsDescriptor">/home/fred/jetty/mywebdefaults.xml</Set> <!-- set to your customized defaults file --> |
− | </New | + | </New> |
− | </Arg | + | </Arg> |
− | </Call | + | </Call> |
− | |||
</source> | </source> | ||
Line 45: | Line 42: | ||
− | <New id="myWebAppContext" | + | <New id="myWebAppContext" class="org.mortbay.jetty.webapp.WebAppContext"> |
− | <Set name="contextPath" | + | <Set name="contextPath">/</Set> |
− | <Set name="war" | + | <Set name="war">./webapps/fredapp</Set> |
− | <Set name="defaultsDescriptor" | + | <Set name="defaultsDescriptor">/home/fred/jetty/mywebdefaults.xml</Set> |
. | . | ||
. | . | ||
− | </New | + | </New> |
</source> | </source> |
Revision as of 17:16, 12 July 2011
Introduction
Jetty buffers static content for webapps such as HTML files, CSS files, images, etc. If you are using NIO connectors, Jetty uses memory-mapped files to do this. The problem is that on Windows, memory mapping a file causes the file to lock, so that you cannot update or replace the file. Effectively this means that you have to stop Jetty to update a file.
Remedy
Jetty provides a configuration switch in the webdefault.xml file for the DefaultServlet that enables or disables the use of memory-mapped files. If you are running on Windows and are having file-locking problems, you should set this switch to disable memory-mapped file buffers.
The default webdefault.xml file is in the lib/jetty.jar at org/eclipse/jetty/webapp/webdefault.xml. Extract it to a convenient disk location and edit it to change useFileMappedBuffer to false.
<init-param> <param-name>useFileMappedBuffer</param-name> <param-value>true</param-value> <!-- change to false --> </init-param>
Make sure to apply your custom webdefault.xml file to all of your webapps. You can do that by changing the configuration of the Deployment Manager in etc/jetty.xml.
<Call name="addLifeCycle"> <Arg> <New class="org.mortbay.jetty.deployer.WebAppDeployer"> <Set name="contexts"><Ref id="Contexts"/></Set> <Set name="webAppDir"><SystemProperty name="jetty.home" default="."/>/webapps</Set> <Set name="parentLoaderPriority">false</Set> <Set name="extract">true</Set>< <Set name="allowDuplicates">false</Set> <Set name="defaultsDescriptor">/home/fred/jetty/mywebdefaults.xml</Set> <!-- set to your customized defaults file --> </New> </Arg> </Call>
Alternatively, if you have individually configured your webapps with context xml files, you need to call the WebAppContext.setDefaultsDescriptor(String path) method:
<New id="myWebAppContext" class="org.mortbay.jetty.webapp.WebAppContext"> <Set name="contextPath">/</Set> <Set name="war">./webapps/fredapp</Set> <Set name="defaultsDescriptor">/home/fred/jetty/mywebdefaults.xml</Set> . . </New>
Alternate Remedy
You can force a WebAppContext to always copy a web app directory on deployment to avoid the file locking issue. Configure this in a context deployment file as follows:
<New id="myWebAppContext" class="org.mortbay.jetty.webapp.WebAppContext"> <Set name="contextPath">/</Set> <Set name="war">./webapps/fredapp</Set> <Set name="copyWebDir">true</Set> . . </New>
You can also configure the default Jetty Servlet directly in the web.xml. For example:
<web-app ...> ... <servlet> <servlet-name>default</servlet-name> <servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class> <init-param> <param-name>useFileMappedBuffer</param-name> <param-value>false</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> ... </web-app>
This might completely redefine the default servlet configuration (not sure about that, if anyone can confirm). You could still simply extract the webdefault file as explained above, and copy-paste the complete default servlet definition in your web.xml, changing that useFileMappedBuffer parameter to false.
(optional) - categor(ies) to use for this page. If blank, will use the template name as a default category Example: