maven工程引用仓库中没有的包

来源:互联网 发布:ledrom编辑软件 编辑:程序博客网 时间:2024/05/01 09:13

普通工程转换成maven工程,有些依赖的jar文件在maven互联网中心仓库中没有,怎么办?


maven引用第三方jar包有如下方法:

一.在工程resource目录创建一个lib文件夹,拷贝jar进去,配置pom.xml 依赖如下:

<dependency>            <groupId>com.test</groupId>            <artifactId>Test</artifactId>            <version>1.0</version>            <scope>system</scope>            <systemPath>${basedir}/src/main/resources/lib/Test.jar</systemPath> </dependency>

二.手动添加jar文件到本地仓库(推荐,原因:第一种打包之后如果被另外的工程引用,lib中的jar包里面的类会找不到,需要打包时配置解压,有点麻烦,而且不能共享使用

1.将test.jar放在一个文件夹里面 比如  test,建一个test.jar包相关的pom.xml文件,需要在pom.xml中定义其maven坐标及(如果有依赖)其相应的依赖代码即可,同样将pom文件存放在上述jar文件同一文件夹下,test.jar坐标及依赖代码如下:

<?xml version="1.0" encoding="UTF-8" ?> - <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>   <groupId>org.test</groupId>   <artifactId>Test</artifactId>   <version>1.0</version>   </project>
2.打开CMD,进入到test文件夹,运行下面命令

mvn install:install-file -Dfile=Test.jar  -DgroupId=org.test  -DartifactId=Test -Dversion=1.0  -Dpackaging=jar

这样你就可以将Test.jar安装到您Maven本地的库文件夹相应目录中。

之后你可以在工程的pom.xml文件中和其它依赖jar包一样通过以下依赖引入上述的包,如下:

<dependency>     <groupId>org.test</groupId>     <artifactId>Test</artifactId>     <version>1.0</version> </dependency>


当然还可以deploy到私服中(见上篇),这样公司其它成员都可以通过依赖引用了




0 0
原创粉丝点击