我们使用Maven从中央库或者从本地库等获取所需要的jar文件,但有的项目文件即不在中央库又不在本地库,需要我们手动下载。

官网地址:https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

外部依赖注入的两种方式:

1. 通过install-file 的形式加入到本地库。 mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code

  -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar
但这种方式,移植到其它地方后,又需要再次加入到另一电脑的本地库。

ojdbc因为牵扯付费因此虽然在mvn上可以看到但是没法下载。
mvn install:install-file -Dfile=D:\Repository\ojdbc14-10.2.0.4.0.jar  -DartifactId=ojdbc14 -DgroupId=com.oracle -Dversion=10.2.0.4.0 -Dpackaging=jar
当导入的jar包的pom文件有依赖时,要一并把pom文件也要导入(-DpomFile),否则依赖包将不会被加载到执行应用中。

>
mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar -DpomFile=c:\pom.xml
同时可以将source包也载入进来:
>mvn install:install-file -Dfile=E:/common-base-0.0.1-sources.jar -DgroupId=net.spy -DartifactId=spymemcached -Dversion=2.10.3 -Dpackaging=jar -Dclassifier=sources

2. 项目中外部依赖
  在src目录下创建lib文件夹,将jar文件放入其中。
  在pom.xml文件中添加以下数据:
  

<dependency>
  <groupId>ojdbc</groupId>
  <artifactId>ojdbc</artifactId>
  <scope>system</scope>
  <version>6</version>
  <systemPath>${basedir}\src\lib\ojdbc-6.jar</systemPath>
</dependency>

保存后,数据会自动进入到Maven Dependency中。

 

 

 



posted on 2017-10-20 14:55  zhaoqiang1980  阅读(286)  评论(0)    收藏  举报