快捷搜索: 王者荣耀 脱发

maven引入本地jar包的三种方式

有些jar包并非可以从在线仓库中下载到的,还有些是自己写的jar包要给其他人用,使用这样的一些jar包总结了3中方式:

方式一: 使用scope 为 system 引入本地jar 不太推荐使用这种方式。 将jar包复制到项目的lib目录中,然后在pom中这样引用:

<dependency>
    <groupId>随便写</groupId>
    <artifactId>随便写</artifactId>
    <version>随便写</version>
    <scope>system</scope>
    <systemPath>${
          
   basedir}/src/main/webapp/WEB-INF/lib/xxxxxxx.jar</systemPath>
</dependency>

b a s e d i r 不 用 改 , 就 这 么 写 , 你 只 用 把 x x x x x x 换 成 你 的 j a r 名 称 就 可 以 了 , {basedir}不用改,就这么写,你只用把xxxxxx换成你的jar名称就可以了, basedir不用改,就这么写,你只用把xxxxxx换成你的jar名称就可以了,{basedir}应该是maven提供的一个变量,代表项目的根目录;

groupId、artifactId、version 这三个不能省略,但可以随便写;

方式二: 有时候我们直接将jar放到本地仓库对应的文件夹中,然后在eclipse里面在项目上右键–>Maven->Update Project… 也行,但有时候又不行,报错提示下载那个jar文件的 xx.pom 失败,所以最好是使用这种方式安装到本地仓库,会自动创建一个xx.pom的文件: 使用maven 命令 将jar包安装到自己的本地仓库,然后在pom中引用,

mvn install:install-file -Dfile=D:/xxxxxx.jar -DgroupId=自定义groupId -DartifactId=自定义artifactId -Dversion=自定义version  -Dpackaging=jar

在pom中就可以这样引用

<dependency>
    <groupId>自定义groupId</groupId>
    <artifactId>自定义artifactId</artifactId>
    <version>自定义version</version>
</dependency>

方式三: 使用maven 命令 将jar包上传到自己搭建的私服中,然后在pom中引用 如何搭建私服、在maven的配置文件中配置自己的私服就不说了,很多文章讲这个。 上传jar包到私服的命令:

mvn deploy:deploy-file -DgroupId=自定义groupId -DartifactId=自定义artifactId -Dversion=自定义version -Dpackaging=jar -Dfile=D:/xxxxxx.jar -Durl=http://私服地址/repository/maven-3rd/ -DrepositoryId=maven-3rd

在pom中就可以这样引用

<dependency>
    <groupId>自定义groupId</groupId>
    <artifactId>自定义artifactId</artifactId>
    <version>自定义version</version>
</dependency>

我一般使用第三种方式

经验分享 程序员 微信小程序 职场和发展