从maven中央仓库下载jar包

1、安装本地jar包到maven本地仓库

mvn install:install-file:主要是将本地自定义jar安装到maven仓库,然后在pom中可以直接通过dependency的方式来引用。

-DgroupId=自定义groupId 设置groupId 名 -DartifactId=自定义artifactId 设置该包artifactId名 -Dversion=自定义版本1.0.0 设置版本号 -Dpackaging=jar 设置该包的类型,有如下值:pom、jar、war、maven-plugin -Dfile=文件路径 设置该jar包文件所在的路径与文件名 完整的命令如下:

mvn install:install-file -DgroupId=com.xxx -DartifactId=maven-test -Dversion=1.0.0 -Dpackaging=jar -Dfile=C:lib	est.jar
注意一定要写绝对地址,我写了相对地址去执行,就不停的刷屏

2、命令行方式从maven中央仓库下载jar到本地仓库

浏览器登录maven中央仓库网址 【maven中央仓库网址】/

先看下图,找到你要下载的

图中红色框的就是你的参数,补全下面的命令行

mvn dependency:get -DremoteRepositories=https://mvnrepository.com/artifact/io.github.XXX/你的jar包名 -DgroupId=io.github.XXX -DartifactId=你的jar包名 -Dversion=版本号

参数 内容 -DremoteRepositories 红框中第一行的网址 -DgroupId 红框中groupId -DartifactId 红框中artifactId -Dversion 红框中version

补全后,打开dos窗口,输入上面命令。 如果没有在你的项目根目录下输入上面命令,十之八九会报错,如下

No plugin found for prefix ‘dependency’ in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo]

原因是maven不识别这个命令dependency,需要在你项目根目录下的pox.xml文件里写上

<plugin>
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>3.0.2</version> 
    <executions> 
      <execution> 
        <id>copy-dependencies</id> 
        <phase>package</phase> 
        <goals> 
          <goal>copy-dependencies</goal> 
        </goals>
      </execution> 
    </executions> 
</plugin>

然后进入项目根目录,再执行你的mvn dependency:get 命令那一大串,就可以下载成功了。如下

3、idea刷新下载

idea开发工具还是很好的,这里就更简单了,刷它。点击下面的红色框。 然后点击开看看里面的dependencies,找到你要下的包。就好了。

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