使用maven項(xiàng)目pom.xml文件配置打包功能和靜態(tài)資源文件自帶版本號功能
更新時(shí)間:2024年09月29日 10:01:36 作者:閑走天涯
在Maven項(xiàng)目中,通過pom.xml文件配置打包功能,可以控制構(gòu)建過程,生成可部署的包,同時(shí),為了緩存控制與版本更新,可以在打包時(shí)給靜態(tài)資源文件如JS、CSS添加版本號,這通常通過插件如maven-resources-plugin實(shí)現(xiàn)
maven項(xiàng)目pom.xml文件配置打包功能和靜態(tài)資源文件自帶版本號功能
例如:
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標(biāo)簽內(nèi)增加
<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打包時(shí)包含resource靜態(tài)文件
<build>
<!-- maven打包時(shí)包含靜態(tài)資源文件 -->
<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>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java事務(wù)管理學(xué)習(xí)之Hibernate詳解
hibernate是jdbc輕量級的封裝,本身不具備事務(wù)管理的能力,在事物管理層面,一般是委托于底層的jdbc和jta來完成調(diào)度的。下面這篇文章主要給大家介紹了Java事務(wù)管理學(xué)習(xí)之Hibernate的相關(guān)資料,需要的朋友可以參考下。2017-03-03
java實(shí)現(xiàn)省市區(qū)三級聯(lián)動
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)省市區(qū)三級聯(lián)動,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06
Java藍(lán)橋杯實(shí)現(xiàn)線段和點(diǎn)
本文主要介紹Java藍(lán)橋杯實(shí)現(xiàn)線段和點(diǎn)的內(nèi)容,感興趣的小伙伴可以參考下文2021-08-08
SpringMVC實(shí)現(xiàn)controller中獲取session的實(shí)例代碼
本篇文章主要介紹了SpringMVC實(shí)現(xiàn)controller中獲取session的實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-02-02
SpringCloud如何使用Eureka實(shí)現(xiàn)服務(wù)之間的傳遞數(shù)據(jù)
這篇文章主要介紹了SpringCloud使用Eureka實(shí)現(xiàn)服務(wù)之間的傳遞數(shù)據(jù)操作,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06

