今天遇到一個mavan倉庫中沒有的jar包, 故只能添加本地jar包, 花了不少時間找資料,終於OK。故在此記錄。
1. 第一次,在網上看到說可以用<systemPath> 解決, 如下:
<dependencies> <dependency> <groupId>xxx</groupId> <artifactId>xxx</artifactId> <version>xxx</version> <scope>system</scope> <systemPath>${basedir}/xx.jar</systemPath> </dependency> </dependencies>
但是,在運行jetty 的以及打包的時候,會找不到引用的包,直接pass掉。各種蛋疼,都是maven不熟惹的禍。故去maven官網看了一下文檔,搗鼓了好一陣兒,終於找到了一個解決辦法:
2. 創建本地倉庫,以plugin的形式進行安裝:
(1)創建本地倉庫:
<repositories> <repository> <id>local-repo</id> <url>file://${basedir}/repo</url> </repository> </repositories>
(2)將本地庫安裝到maven:
mvn install:install-file -Dfile=<jar-path> -DgroupId=<group> -DartifactId=<artifactId> -Dversion=<version> -Dpackaging=<packaging> -DlocalRepositoryPath=<path>
(注:參數說明:jar-path 為你的jar所在路徑, group,artifactId, version 這個不多說, packaging 為jar或war, DlocalRepositoryPath是你之前創建的本地倉庫的路徑)。
(3) 以插件形式安裝:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.4</version> <executions> <execution> <phase>initialize</phase> <goals> <goal>install-file</goal> </goals> <configuration> <groupId>xxx</groupId> <artifactId>xxx</artifactId> <version>xxx</version> <packaging>jar</packaging> <file>${basedir}/xxx.jar</file> </configuration> </execution> </executions> </plugin>
(4) 添加依賴:
<dependency> <artifactId>xxx</artifactId> <groupId>xxx</groupId> <version>xxx</version> </dependency>
ok, 到此就ok啦。 由於對maven不是太熟,的確花了不少時間去看資料。特在此記錄,一來留個筆記,而來希望能幫助到遇到同樣問題的人。