3

我正在 Eclipse 中开发一个 javascript 项目。静态 html 和 javascript 文件需要访问我的服务的 restful 端点,所以我将它们放在带有这些端点的 java 项目中,这样我就可以访问它们而不会出现跨域问题。

但是,突然之间,如果我尝试保存对我的 html 文件的更改,除非我停止运行 java 应用程序,否则我不能。

事件的顺序是这样的:

Run java web app with Jetty

Can save changes to html file.

Open html file in chrome with url: http://127.0.0.1:8901/myapp/myapp-admin.html

Cannot save changes to html file.

Close chrome.

Still can't save changes.

Stop jetty running in eclipse.

Can save changes.

当我尝试保存时,出现以下错误:

Save could not be completed. Try File > Save As... if the problem persists.

Reason:
Could not write file:
C:\{path to file}\myapp-admin.html

(The requested operation cannot be performed on a file with a user-mapped section open)

如果我尝试使用 save as 覆盖该文件,它仍然无法正常工作,并出现错误:

Save could not be completed. Could not write file: {etc.}

这是html文件:

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>


<title>myapp Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <h1>myapp</h1>

</body>
</html>

我唯一改变的是这些在 web.xml 中的映射方式。基本上,在我使用弹簧控制器等以弹簧方式渲染它们之前。

现在我正在静态渲染它们,使用:

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.html</url-pattern>
    <url-pattern>*.js</url-pattern>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>

但我不知道为什么会导致这种问题。

Spring的映射如下:

<!-- Declare a Spring MVC DispatcherServlet as usual -->
<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- Configure DispatcherServlet to use AnnotationConfigWebApplicationContext 
        instead of the default XmlWebApplicationContext -->
    <init-param>
        <param-name>contextClass</param-name>
        <param-value>
          org.springframework.web.context.support.AnnotationConfigWebApplicationContext
      </param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

谁能帮我弄清楚这里出了什么问题,以及是否有办法让它像我想要的那样工作?

4

3 回答 3

7

您在 Windows 上遇到了经典的文件锁定问题。(这不会发生在任何版本的 unix、linux 或 osx 上)

尝试按照Windows 上的锁定文件疑难解答中的指南为您的特定 web 应用禁用 Jetty 的高级性能功能。

(链接到 Jetty 9 文档,因为您没有指定您使用的 Jetty 版本)

于 2013-06-13T03:49:44.650 回答
1

事实证明,使用 Jetty 8.1.9 需要一个不同的解决方案。正如这个答案所描述的,我必须将 maxCachedFiles 设置为 0。

于 2013-06-13T16:26:09.373 回答
0

我通过从 Jetty 切换到 Tomcat 解决了这个问题。我只是使用 Maven 插件,所以切换时间为 30 秒。我不明白为什么您必须专门配置它,因为它是在您的开发环境中进行热部署的一项功能。为此,我不相信 Jetty 解决了一个问题,而是创造了一个新问题。

于 2015-01-14T15:54:10.677 回答