java 如何防止MVN在打包WAR文件时更改文件日期?

oewdyzsn  于 2024-01-05  发布在  Java
关注(0)|答案(1)|浏览(232)

我有一个带有大量JSP文件的TomCat应用程序。我最近从Gradle切换到MVN进行构建。一个很大的区别是MVN构建将所有JSP文件上的时间戳设置为构建时间。我不希望这样做有两个原因。首先,它会导致不必要的传输到未打包的JSP文件的服务,因为时间戳表明它们已经更改,而实际上它们没有更改。第二个是在测试/调试阶段,我在TomCat服务器上编辑JSP文件,我需要时间戳准确地显示文件最后一次更改的日期。
我在某个地方看到一个提示,这可能是由于MVN将行尾从Unix更改为Windows或其他什么。我也不希望它这样做。我看到<lineEnding>KEEP</lineEnding>的设置,我已经将其放在POM文件的各个地方,但没有效果。我不知道这是否是问题。
这里是我的整个POM文件,如果这有助于

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.mycompany.app</groupId>
  5. <artifactId>my-app</artifactId>
  6. <version>1.0-SNAPSHOT</version>
  7. <packaging>war</packaging>
  8. <properties>
  9. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  10. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  11. <maven.compiler.source>17</maven.compiler.source>
  12. <maven.compiler.target>8</maven.compiler.target>
  13. </properties>
  14. <dependencies>
  15. <dependency>
  16. <groupId>junit</groupId>
  17. <artifactId>junit</artifactId>
  18. <version>4.13.2</version>
  19. <scope>test</scope>
  20. </dependency>
  21. <!-- https://mvnrepository.com/artifact/com.purplehillsbooks.purple/purple -->
  22. <dependency>
  23. <groupId>com.purplehillsbooks.purple</groupId>
  24. <artifactId>purple</artifactId>
  25. <version>3.1</version>
  26. </dependency>
  27. <!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
  28. <dependency>
  29. <groupId>org.jsoup</groupId>
  30. <artifactId>jsoup</artifactId>
  31. <version>1.17.1</version>
  32. </dependency>
  33. <!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
  34. <dependency>
  35. <groupId>javax.servlet</groupId>
  36. <artifactId>servlet-api</artifactId>
  37. <version>2.5</version>
  38. <scope>provided</scope>
  39. </dependency>
  40. <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
  41. <dependency>
  42. <groupId>org.apache.tomcat</groupId>
  43. <artifactId>tomcat-catalina</artifactId>
  44. <version>11.0.0-M15</version>
  45. <scope>provided</scope>
  46. </dependency>
  47. <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
  48. <dependency>
  49. <groupId>org.apache.httpcomponents</groupId>
  50. <artifactId>httpcore</artifactId>
  51. <version>4.4.11</version>
  52. </dependency>
  53. <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
  54. <dependency>
  55. <groupId>org.apache.httpcomponents</groupId>
  56. <artifactId>httpclient</artifactId>
  57. <version>4.5.14</version>
  58. </dependency>
  59. </dependencies>
  60. <build>
  61. <plugins>
  62. <plugin>
  63. <artifactId>maven-compiler-plugin</artifactId>
  64. <version>3.8.1</version>
  65. <configuration>
  66. <source>8</source>
  67. <target>8</target>
  68. <lineEnding>KEEP</lineEnding>
  69. </configuration>
  70. </plugin>
  71. <plugin>
  72. <artifactId>maven-war-plugin</artifactId>
  73. <configuration>
  74. <lineEnding>keep</lineEnding>
  75. <attachClasses>true</attachClasses>
  76. <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
  77. <webResources>
  78. <resource>
  79. <directory>src/main/webapp</directory>
  80. <filtering>true</filtering>
  81. </resource>
  82. </webResources>
  83. </configuration>
  84. </plugin>
  85. </plugins>
  86. </build>
  87. </project>

字符串

fcipmucu

fcipmucu1#

给你两个建议。第一个是,如果你需要maven-war-plugin的所有配置,那么删除filtering命令。Maven正在做你告诉它的事情-读取每个文件并查看是否有替换。它会按照指示写出新文件。
但你的配置是标准的-我只需要:

  1. <plugin>
  2. <artifactId>maven-war-plugin</artifactId>
  3. <version>3.2.2</version>
  4. </plugin>

字符串
它将默认为您想要的-JSP将保持它最初拥有的时间戳。

相关问题