使用maven項目pom.xml文件配置打包功能和靜態(tài)資源文件自帶版本號功能
更新時間:2024年09月29日 10:01:36 作者:閑走天涯
在Maven項目中,通過pom.xml文件配置打包功能,可以控制構建過程,生成可部署的包,同時,為了緩存控制與版本更新,可以在打包時給靜態(tài)資源文件如JS、CSS添加版本號,這通常通過插件如maven-resources-plugin實現(xiàn)
maven項目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標簽內(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打包時包含resource靜態(tài)文件
<build> <!-- maven打包時包含靜態(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>
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
SpringBoot中@ConfigurationProperties 配置綁定
本文主要介紹了SpringBoot中@ConfigurationProperties 配置綁定,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11JDBC操作數(shù)據(jù)庫的增加、刪除、更新、查找實例分析
這篇文章主要介紹了JDBC操作數(shù)據(jù)庫的增加、刪除、更新、查找方法,以完整實例形式分析了Java基于JDBC連接數(shù)據(jù)庫及進行數(shù)據(jù)的增刪改查等技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10Java 實戰(zhàn)項目錘煉之校園宿舍管理系統(tǒng)的實現(xiàn)流程
讀萬卷書不如行萬里路,只學書上的理論是遠遠不夠的,只有在實戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+jsp+javaweb+mysql+ajax實現(xiàn)一個校園宿舍管理系統(tǒng),大家可以在過程中查缺補漏,提升水平2021-11-11Redisson分布式閉鎖RCountDownLatch的使用詳細講解
分布式鎖和我們java基礎中學習到的synchronized略有不同,synchronized中我們的鎖是個對象,當前系統(tǒng)部署在不同的服務實例上,單純使用synchronized或者lock已經(jīng)無法滿足對庫存一致性的判斷。本次主要講解基于rediss實現(xiàn)的分布式鎖2023-02-02