Maven引入本地Jar包并打包進War包中的方法
1.概述
在平時的開發(fā)中,有一些Jar包因為種種原因,在Maven的中央倉庫中沒有收錄,所以就要使用本地引入的方式加入進來。
2. 拷貝至項目根目錄
項目根目錄即pom.xml文件所在的同級目錄,可以在項目根目錄下創(chuàng)建文件夾lib,如下圖所示:
這4個Jar包是識別網(wǎng)頁編碼所需的包。
3. 配置pom.xml,依賴本地Jar
配置Jar的dependency,包括groupId,artifactId,version三個屬性,同時還要包含scope和systemPath屬性,分別指定Jar包來源于本地文件,和本地文件的所在路徑。
<!-- ################################# cpdetector #################################### --> <dependency> <groupId>cpdetector</groupId> <artifactId>cpdetector</artifactId> <version>1.0.10</version> <scope>system</scope> <systemPath>${basedir}/lib/cpdetector_1.0.10.jar</systemPath> </dependency> <dependency> <groupId>antlr</groupId> <artifactId>antlr</artifactId> <version>2.7.4</version> <scope>system</scope> <systemPath>${basedir}/lib/antlr-2.7.4.jar</systemPath> </dependency> <dependency> <groupId>chardet</groupId> <artifactId>chardet</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${basedir}/lib/chardet-1.0.jar</systemPath> </dependency> <dependency> <groupId>jargs</groupId> <artifactId>jargs</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${basedir}/lib/jargs-1.0.jar</systemPath> </dependency>
其中,${basedir}是指項目根路徑
4. 配置Maven插件將本地Jar打包進War中
在進行以上配置以后,編寫代碼時已經(jīng)可以引入Jar包中的class了,但是在打包時,由于scope=system,默認并不會將Jar包打進war包中,所有需要通過插件進行打包。
修改pom.xml文件,在plugins標(biāo)簽下加入下面的代碼
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>copy-dependencies</id> <phase>compile</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory> <includeScope>system</includeScope> </configuration> </execution> </executions> </plugin>
這樣,打出來的war包中,就會包含本地引入的jar依賴了。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java實現(xiàn)文件壓縮與解壓的示例[zip格式,gzip格式]
本篇文章主要介紹了Java實現(xiàn)文件壓縮與解壓的示例[zip格式,gzip格式],具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-01-01Intellij IDEA使用restclient測試的教程圖解
這篇文章主要介紹了Intellij IDEA使用restclient測試的教程圖解,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01Mybatis應(yīng)用mysql存儲過程查詢數(shù)據(jù)實例
下面小編就為大家分享一篇Mybatis應(yīng)用mysql存儲過程查詢數(shù)據(jù)實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12