赞
踩
问题一:
经常遇到公司私服或者中央仓库没有的jar包,然后通过各种渠道找到了解决问题的jar包,但是发现没有pom文件,maven项目引入之后,还有maven在本地仓库找不到对应jar包的pom文件,打包的时候会在私服下载对应jar包的pom文件而抛出异常,通过maven就可以解决这个问题。前提是你安装了maven,然后在命令行执行命令就OK了!!!
- [ERROR] Failed to execute goal on project AccountEJob: Could not resolve dependencies for project AccountEJob:AccountEJob:jar:1.1.1: Failed to collect dependencies at org.apache.hive:hive-jdbc:jar:1.2.1000.2.6.1.0-129: Failed to read artifact descriptor for org.apache.hive:hive-jdbc:jar:1.2.1000.2.6.1.0-129: Could not transfer artifact org.apache.hive:hive-jdbc:pom:1.2.1000.2.6.1.0-129 from/to nexus (http://XXX.XXX.XXX.XXX:8081/nexus/content/groups/public): Connect to XXX.XXX.XXX.XXX:8081/ [/XXX.XXX.XXX.XXX:8081/] failed: Connection timed out: connect -> [Help 1]
- [ERROR]
- [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
- [ERROR] Re-run Maven using the -X switch to enable full debug logging.
- [ERROR]
- [ERROR] For more information about the errors and possible solutions, please read the following articles:
- [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
命令:
mvn install:install-file -DgroupId=novaplanet.net -DartifactId=commons-lang -Dversion=2.5 -Dfile=F:/commons-lang-2.5.jar -Dpackaging=jar -DgeneratePom=true
DgroupId:项目组织唯一的标识符,自己随便起名
DartifactId:项目唯一的标识符,自己可以随便起
Dversion:项目版本
Dfile:jar包路径(绝对路径)
DgeneratePom:是否生成pom文件,ture:生成,false:不生成
执行成功,会在本地的maven jar包目录看到以下结果
问题二:
自己本地的jar包,公司私服上没有,如何引用?先在项目的resource目录下新建lib文件夹,然后将你本地的jar包copy过去(这种最好上传至公司私服)
在maven的配置如下:
- <dependencies>
- <dependency>
- <groupId>novaplanet.net</groupId>
- <artifactId>javapns-jdk16-163</artifactId>
- <version>1.2</version>
- <scope>system</scope>
- <systemPath>${project.basedir}/src/main/resources/lib/javapns-jdk16-163-1.2.jar</systemPath>
- </dependency>
- </dependencies>
build插入下面配置:
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <includeSystemScope>true</includeSystemScope>
- </configuration>
- </plugin>
- </plugins>
- </build>
我的实例配置:
- <?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>com.teset</groupId>
- <artifactId>demo</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>jar</packaging>
-
- <name>demo</name>
- <description>Demo project for Spring Boot</description>
-
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.0.3.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <java.version>1.8</java.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>novaplanet.net</groupId>
- <artifactId>bcprov-jdk16-145</artifactId>
- <version>1.2</version>
- <scope>system</scope>
- <systemPath>${project.basedir}/src/main/resources/lib/bcprov-jdk16-145-1.2.jar</systemPath>
- </dependency>
- <dependency>
- <groupId>novaplanet.net</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.5</version>
- <scope>system</scope>
- <systemPath>${project.basedir}/src/main/resources/lib/commons-lang-2.5.jar</systemPath>
- </dependency>
- <dependency>
- <groupId>novaplanet.net</groupId>
- <artifactId>javapns-jdk16-163</artifactId>
- <version>1.2</version>
- <scope>system</scope>
- <systemPath>${project.basedir}/src/main/resources/lib/javapns-jdk16-163-1.2.jar</systemPath>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <includeSystemScope>true</includeSystemScope>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </project>
引入之后,编译项目,编译成功不一定代表引入成功了,接着打包,看jar包中的classes下的lib中有没有你需要引入的jar包
1、可能是jar的坐标有问题,即groupId、artifactId、version拼写有问题;
2、jar包压根就不存在;
3、私服镜像地址有问题;
4、网络问题,比如本地无法使用ipv6网络,需要强制指定ipv4,具体操作请查看这篇文章
由于以上问题,导致jar包无法下载,会在对于的路径下,生成.lastUpdated文件,所以我们需要删除本地仓库.lastUpdated重新下载,要不然会影响再次下载和后续的编译运行。
linux、macos环境下,批量删除
find 私服路径 -name "*lastUpdated*" | xargs rm -rf
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。