maven项目pom.xml文件配置打包功能和静态资源文件自带版本号功能
例如:
html文件中引用js文件
<script src="js/jquery-2.0.2.min.js"></script>
打包编译后会变成
<script src="js/jquery-2.0.2.min.js?v=2021-07-09T09:29:42Z"></script>
pom.xml标签内增加
<build> <plugins> <!--配置打包 start--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!--配置打包 end--> <!--配置页面文件自带版本号 start--> <plugin> <groupId>com.google.code.maven-replacer-plugin</groupId> <artifactId>replacer</artifactId> <version>1.5.3</version> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>replace</goal> </goals> </execution> </executions> <configuration> <includes> <include>${basedir}/target/classes/templates/**/*.html</include> </includes> <replacements> <replacement> <token>\.js\"</token> <value>.js?v=${maven.build.timestamp}\"</value> </replacement> <replacement> <token>\.js\'</token> <value>.js?v=${maven.build.timestamp}\'</value> </replacement> <replacement> <token>\.css\"</token> <value>.css?v=${maven.build.timestamp}\"</value> </replacement> <replacement> <token>\.css\'</token> <value>.css?v=${maven.build.timestamp}\'</value> </replacement> </replacements> </configuration> </plugin> <!--配置页面文件自带版本号 end--> </plugins> </build>
maven打包时包含resource静态文件
<build> <!-- maven打包时包含静态资源文件 --> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.yaml</include> <include>META-INF/**</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
您可能感兴趣的文章: