1. 程式人生 > >將本地jar新增到Maven倉庫

將本地jar新增到Maven倉庫

一、將jar新增到本地倉庫的做法:

以下面pom.xml依賴的jar包為例:

實際專案中pom.xml依賴寫法:

  1. <dependency>
  2.     <groupId>org.springframework</groupId>
  3.     <artifactId>spring-context-support</artifactId>
  4.     <version>3.1.0.RELEASE</version>
  5. </dependency>

Maven 安裝 JAR 包的命令是:

-DgroupId=上面的groupId   

-DartifactId=上面的artifactId   -Dversion=上面的version

這三自定義的,寧外不要回車 

  1. mvn install:install-file   
  2. -Dfile=jar包的位置   
  3. -DgroupId=上面的groupId   
  4. -DartifactId=上面的artifactId   
  5. -Dversion=上面的version   
  6. -Dpackaging=jar

例如我的這個spring-context-support-3.1.0.RELEASE.jar 檔案放在了"D:\mvn\"中

則命令為:

mvn install:install-file 

-Dfile=D:\mvn\spring-context-support-3.1.0.RELEASE.jar 

-DgroupId=org.springframework 

-DartifactId=spring-context-support 

-Dversion=3.1.0.RELEASE 

-Dpackaging=jar

注意:任何路徑和名稱不要有中文和空格,以防出現莫名其妙的錯誤。

二、不講jar包新增到本地倉庫也可在maven工程中使用外部jar包的做法:

假設將包htmlparser.jar放入了專案下的lib目錄中 : -> ${project}/lib/htmlparser.jar
則pom.xml檔案中依賴可以如下:
  1. <dependency>
  2.     <groupId>com.htmlparser</groupId>
  3.     <artifactId>htmlparser</artifactId>
  4.     <version>2.0</version>
  5.     <scope>system</scope>
  6.     <systemPath>${project.basedir}/lib/htmlparser.jar</systemPath>
  7. </dependency>