我有一个包含大量 JSP 文件的 TomCat 应用程序。我最近从 Gradle 切换到 MVN 进行构建。一大区别是 MVN 构建将所有 JSP 文件上的时间戳设置为构建时间。我不想要这个有两个原因。首先,它会导致不必要地传输到解压的 JSP 文件的服务,因为时间戳表明它们已更改,而实际上它们并未更改。其次,在测试/调试阶段,我在 TomCat 服务器上编辑 JSP 文件,我需要时间戳来准确显示文件上次更改的日期。
我在某处看到一个提示,这可能是由于 MVN 将行结尾从 Unix 更改为 Windows 或其他原因。我也不希望它这样做。我看到了
<lineEnding>KEEP</lineEnding>
的设置,我已将其放入 POM 文件中的各个位置,但没有效果。不知道是不是这个问题。
如果有帮助的话,这是我的整个 POM 文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.purplehillsbooks.purple/purple -->
<dependency>
<groupId>com.purplehillsbooks.purple</groupId>
<artifactId>purple</artifactId>
<version>3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.17.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>11.0.0-M15</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<lineEnding>KEEP</lineEnding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<lineEnding>keep</lineEnding>
<attachClasses>true</attachClasses>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
给你两个建议。第一个是,如果您需要
maven-war-plugin
的所有配置,请删除 filtering
命令。 Maven 正在执行您告诉它的操作 - 读取每个文件并查看是否有替换。它按照指示写出新文件。
但是你的配置是标准的 - 我只想:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
它将默认为您想要的 - JSP 将保留它最初具有的时间戳。