手动将本地jar添加到Maven仓库

向右看齐 2022-07-26 04:29 419阅读 0赞

一、将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 包的命令是:

  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包中央仓库不存在,导致的执行package时出现以下异常

  1. Failed to execute goal on project relayserver: Could not resolve dependencies for project com.xxx:xxx:war:1.0-SNAPSHOT: Failure to find xxx.xxx:xxx:jar:1.0 in http://maven.aliyun
  2. .com/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of nexus-aliyun has elapsed or updates are forced

二、不讲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>

发表评论

表情:
评论列表 (有 0 条评论,419人围观)

还没有评论,来说两句吧...

相关阅读

    相关 jar添加本地maven仓库

    在看《算法第四版》的时候,为了能更轻松的实现书上的案例,从提供的网站下了一个官方提供的标准库(jar包)。开始是在简单的Java项目中用IDEA导入,但发现项目包路径下的类无法