Tomcat自动解压WAR文件更改了文件的最后修改时间

发布于 2024-12-06 20:38:58 字数 339 浏览 4 评论 0原文

当我尝试将 WAR 文件部署到 tomcat 时遇到问题。 在 tomcat 自动解包过程中,解包文件的最后修改日期被修改。 解压 Web 应用程序的日期。文件速度加快了 12 小时,这导致了一些其他错误。

我尝试通过 jar -xvf 手动解压,文件的最后修改日期保持不变。 我还在本地 tomcat 中进行了测试(与开发环境相同的时区),上次修改日期没有任何变化。

看来是tomcat时区问题,我可以在tomcat上进行设置来解决这个问题吗? 非常感谢您的帮助。

环境: Linux 上的 Tomcat 6,服务器和 tomcat 中均设置 GMT-4 时区 设置为 GMT+8 时区的机器创建的 WAR 文件

I experienced an issue when I tried to deploy a WAR file to tomcat.
While the auto unpack process from tomcat, the last modified date of unpack files were being modified.
The date of unpack web app. files became 12 hours faster, and this results several miscellaneous errors.

I tried to unpack manually via jar -xvf, the last modified date of files remain unchanged.
I also tested in a local tomcat (same timezone with dev. env.), nothing changed in last modified date.

It seems the tomcat timezone issue, does setup on tomcat I can do to solve out this issue?
Great thanks for any help.

Environment:
Tomcat 6 on linux, with GMT-4 timezone both set in server and tomcat
the WAR file created by machine with GMT+8 timezone set

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生戏 2024-12-13 20:38:58

就我而言,应用程序在初始化时从 Tomcat 中设置默认时区。时区更改带来的差异与文件修改时间的偏移量相匹配。

令我惊讶的是,应用程序中的任何代码都可以在解包之前运行,但 Tomcat 容器确实为应用程序提供了在解包所有文件之前运行初始化代码的机会。

查找 TimeZone.setDefault() 的出现,并尝试删除该调用或将调用移至初始化序列的稍后位置。

有用的线索:

这个 JSP 告诉我,无论环境设置如何,应用程序始终以特定时区运行:

<html> 
<body> 
<h2>Current Timezone</h2> 
<%    java.util.Date date = new java.util.Date();       
      java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("zzz"); %> 
<%=sdf.format(date)%> 
</body> 
</html>

在日志文件中,我可以看到时区更改的瞬间(四小时跳跃)。它发生在应用程序加载时。

注意:设置后,时区将保持设置状态,直到 Tomcat 重新启动。

Sep 18, 2015 2:34:26 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8443
Sep 18, 2015 2:34:26 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 285 ms
Sep 18, 2015 2:34:26 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Sep 18, 2015 2:34:26 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Sep 18, 2015 2:34:26 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive myWebapp.war
Sep 18, 2015 6:34:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Sep 18, 2015 6:34:34 PM org.apache.catalina.core.ApplicationContext log
INFO: org.tuckey.web.filters.urlrewrite.UrlRewriteFilter INFO: loaded (conf ok)
Sep 18, 2015 6:34:34 PM org.apache.catalina.core.ApplicationContext log
INFO: struts: []: Verifying ModuleConfig for this module
Sep 18, 2015 6:34:34 PM org.apache.catalina.core.ApplicationContext log
INFO: struts: []: Verification of ModuleConfig has been completed
Sep 18, 2015 6:34:34 PM org.apache.catalina.core.ApplicationContext log
INFO: struts: []: Verifying ModuleConfig for this module

In my case, the application was setting the default timezone from within Tomcat as the application was being initialized. The difference introduced by the change in timezones matched the offset in the file modification times.

I was surprised that any code within the app could run before being unpacked, but the Tomcat container does give the application an opportunity to run initialization code prior to all files being unpacked.

Look for an occurrence of TimeZone.setDefault() and try removing the call or moving the call later in the initialization sequence.

Helpful clues:

This JSP told me that the application was always running with a specific timezone regardless of the environment settings:

<html> 
<body> 
<h2>Current Timezone</h2> 
<%    java.util.Date date = new java.util.Date();       
      java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("zzz"); %> 
<%=sdf.format(date)%> 
</body> 
</html>

In the log files, I could see the instant the timezone was changing (four hour jump). It happens at the time the app is loaded.

Note: Once set, the timezone will stay set until Tomcat is restarted.

Sep 18, 2015 2:34:26 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8443
Sep 18, 2015 2:34:26 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 285 ms
Sep 18, 2015 2:34:26 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Sep 18, 2015 2:34:26 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Sep 18, 2015 2:34:26 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive myWebapp.war
Sep 18, 2015 6:34:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Sep 18, 2015 6:34:34 PM org.apache.catalina.core.ApplicationContext log
INFO: org.tuckey.web.filters.urlrewrite.UrlRewriteFilter INFO: loaded (conf ok)
Sep 18, 2015 6:34:34 PM org.apache.catalina.core.ApplicationContext log
INFO: struts: []: Verifying ModuleConfig for this module
Sep 18, 2015 6:34:34 PM org.apache.catalina.core.ApplicationContext log
INFO: struts: []: Verification of ModuleConfig has been completed
Sep 18, 2015 6:34:34 PM org.apache.catalina.core.ApplicationContext log
INFO: struts: []: Verifying ModuleConfig for this module
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文