1.概述
在平時的開發(fā)中,有一些Jar包因?yàn)榉N種原因,在Maven的中央倉庫中沒有收錄,所以就要使用本地引入的方式加入進(jìn)來。
2. 拷貝至項(xiàng)目根目錄
項(xiàng)目根目錄即pom.xml文件所在的同級目錄,可以在項(xiàng)目根目錄下創(chuàng)建文件夾lib,如下圖所示:
這4個Jar包是識別網(wǎng)頁編碼所需的包。
3. 配置pom.xml,依賴本地Jar
配置Jar的dependency,包括groupId,artifactId,version三個屬性,同時還要包含scope和systemPath屬性,分別指定Jar包來源于本地文件,和本地文件的所在路徑。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<!-- ################################# 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}是指項(xiàng)目根路徑
4. 配置Maven插件將本地Jar打包進(jìn)War中
在進(jìn)行以上配置以后,編寫代碼時已經(jīng)可以引入Jar包中的class了,但是在打包時,由于scope=system,默認(rèn)并不會將Jar包打進(jìn)war包中,所有需要通過插件進(jìn)行打包。
修改pom.xml文件,在plugins標(biāo)簽下加入下面的代碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
< 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í)有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:http://blog.csdn.net/upshi/article/details/69948505