问题描述
我正在构建Java Web应用程序,我讨厌传统的代码编译 - 部署 - 测试循环。我想输入一个微小的变化,然后立即查看结果,而不必编译和部署。
I am building Java web applications, and I hate the traditional "code-compile-deploy-test" cycle. I want to type in one tiny change, then see the result INSTANTLY, without having to compile and deploy.
幸运的是,非常棒。它是一个纯java的Web服务器。它附带了一个非常好的,可让您直接启动Jetty阅读来自您的构建树 - 无需打包war文件或部署。它甚至还有一个scanInterval设置:将它设置为非零值,它将监视您的java文件和各种配置文件以进行更改,并在您进行更改后自动重新部署几秒钟。
Fortunately, Jetty is great for this. It is a pure-java web server. It comes with a really nice maven plugin which lets you launch Jetty reading directly from your build tree -- no need to package a war file or deploy. It even has a scanInterval setting: put this to a non-zero value and it will watch your java files and various config files for changes and automatically re-deploy a few seconds after you make a change.
只有一件事让我远离天堂。我的src / main / webapp目录中有javascript和css文件,这些文件只能由Jetty提供。我希望能够编辑这些,并在浏览器中刷新页面时显示更改。不幸的是,Jetty将这些文件保持打开状态,因此我不能(在Windows上)在运行时修改它们。
There's just one thing keeping me from nirvana. I have javascript and css files in my src/main/webapp directory which just get served up by Jetty. I would like to be able to edit these and have the changes show up when I refresh the page in the browser. Unfortunately, Jetty holds these files open so I can't (on Windows) modify them while it is running.
有没有人知道如何让Jetty放开这些文件所以我可以编辑它们,然后为后续请求提供编辑后的文件?
Does anyone know how to make Jetty let go of these files so I can edit them, then serve up the edited files for subsequent requests?
推荐答案
Jetty使用内存映射文件缓冲静态content,导致Windows中的文件锁定。尝试将DefaultServlet的useFileMappedBuffer设置为false。
Jetty uses memory-mapped files to buffer static content, which causes the file-locking in Windows. Try setting useFileMappedBuffer for DefaultServlet to false.
有说明。
这篇关于如何让Jetty动态加载“静态”网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!