Saturday, May 25, 2013

Windows Locked files in Jetty Maven Plugin

If you are developing Java webapps using maven on Windows and using jetty:run to deploy, you have surely come across the problem when you cannot save html, js or vm files. JSPs work fine because they are compiled and deployed. Its surely irritating when that happens.

Jetty has documentation to explain the problem. Many web searches will point to this document. The problem is basically with the NIO connector that jetty uses. Others have suggested that using the old BIO connector is easy way to solve this. The problem is that the Jetty documentation solution requires using a hardcoded location for the new webdefaults.xml. We don’t want to make changes to the source of our project, just because we are on Windows.

My suggested solution is to just edit the maven jetty plugin to not use the FileMappedBuffer. Edit the webdefault.xml that is found in the jar file and that’s all. Browse to your maven repo location. e.g. for 6.1.26 of the plugin go here – USERHOME\.m2\repository\org\mortbay\jetty\jetty\6.1.26\jetty-6.1.26.jar . Open the jar file and find the file at org/mortbay/jetty/webapp/webdefault.xml , and edit the file:

<param-value>false</param-value> <!—change from true to false -->

Save the file and replace the jar with this file. Now whenever you run jetty:run, it will use this file and you will not find windows locking the files when jetty deploys it

No comments: