我编写了一个Java Web应用程序,我在构建时将URL替换为静态内容,以添加版本信息,主要用于缓存.
例如,href="myapp/css/default.min.css"变成了href="myapp-0.2.8/css/default.min.css"
我正在使用maven maven-replacer-plugin,对于一个文件,工作正常:
使用file-Tag进行单个文件替换.
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreMissingFile>false</ignoreMissingFile>
<file>${project.build.directory}/myApp/index.jsp</file>
<replacements>
<replacement>
<token>%PROJECT_VERSION%</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Maven Debug Output在工作示例中显示了这一点.
[DEBUG] Configuring mojo 'com.google.code.maven-replacer-plugin:replacer:1.5.2:replace' with basic configurator -->
[DEBUG] (s) basedir = .
[DEBUG] (s) commentsEnabled = true
[DEBUG] (s) encoding = UTF-8
[DEBUG] (s) file = /Users/phisch/Development/MyApp/Workspace/MyApp-WebApp/target/myApp/index.jsp
[DEBUG] (s) ignoreErrors = false
[DEBUG] (s) ignoreMissingFile = false
[DEBUG] (s) preserveDir = true
[DEBUG] …Run Code Online (Sandbox Code Playgroud)