当前位置:   article > 正文

通过maven,给没有pom文件的jar包生成pom文件,maven项目引入本地jar包_maven只有jar没有pom行吗

maven只有jar没有pom行吗

问题一:

经常遇到公司私服或者中央仓库没有的jar包,然后通过各种渠道找到了解决问题的jar包,但是发现没有pom文件,maven项目引入之后,还有maven在本地仓库找不到对应jar包的pom文件,打包的时候会在私服下载对应jar包的pom文件而抛出异常,通过maven就可以解决这个问题。前提是你安装了maven,然后在命令行执行命令就OK了!!!

  1. [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]
  2. [ERROR]
  3. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  4. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  5. [ERROR]
  6. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  7. [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的配置如下:

  1. <dependencies>
  2. <dependency>
  3. <groupId>novaplanet.net</groupId>
  4. <artifactId>javapns-jdk16-163</artifactId>
  5. <version>1.2</version>
  6. <scope>system</scope>
  7. <systemPath>${project.basedir}/src/main/resources/lib/javapns-jdk16-163-1.2.jar</systemPath>
  8. </dependency>
  9. </dependencies>

build插入下面配置:

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.springframework.boot</groupId>
  5. <artifactId>spring-boot-maven-plugin</artifactId>
  6. <configuration>
  7. <includeSystemScope>true</includeSystemScope>
  8. </configuration>
  9. </plugin>
  10. </plugins>
  11. </build>

我的实例配置:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.teset</groupId>
  6. <artifactId>demo</artifactId>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <packaging>jar</packaging>
  9. <name>demo</name>
  10. <description>Demo project for Spring Boot</description>
  11. <parent>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-parent</artifactId>
  14. <version>2.0.3.RELEASE</version>
  15. <relativePath/> <!-- lookup parent from repository -->
  16. </parent>
  17. <properties>
  18. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  19. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  20. <java.version>1.8</java.version>
  21. </properties>
  22. <dependencies>
  23. <dependency>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter-web</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework.boot</groupId>
  29. <artifactId>spring-boot-starter-test</artifactId>
  30. <scope>test</scope>
  31. </dependency>
  32. <dependency>
  33. <groupId>novaplanet.net</groupId>
  34. <artifactId>bcprov-jdk16-145</artifactId>
  35. <version>1.2</version>
  36. <scope>system</scope>
  37. <systemPath>${project.basedir}/src/main/resources/lib/bcprov-jdk16-145-1.2.jar</systemPath>
  38. </dependency>
  39. <dependency>
  40. <groupId>novaplanet.net</groupId>
  41. <artifactId>commons-lang</artifactId>
  42. <version>2.5</version>
  43. <scope>system</scope>
  44. <systemPath>${project.basedir}/src/main/resources/lib/commons-lang-2.5.jar</systemPath>
  45. </dependency>
  46. <dependency>
  47. <groupId>novaplanet.net</groupId>
  48. <artifactId>javapns-jdk16-163</artifactId>
  49. <version>1.2</version>
  50. <scope>system</scope>
  51. <systemPath>${project.basedir}/src/main/resources/lib/javapns-jdk16-163-1.2.jar</systemPath>
  52. </dependency>
  53. </dependencies>
  54. <build>
  55. <plugins>
  56. <plugin>
  57. <groupId>org.springframework.boot</groupId>
  58. <artifactId>spring-boot-maven-plugin</artifactId>
  59. <configuration>
  60. <includeSystemScope>true</includeSystemScope>
  61. </configuration>
  62. </plugin>
  63. </plugins>
  64. </build>
  65. </project>

引入之后,编译项目,编译成功不一定代表引入成功了,接着打包,看jar包中的classes下的lib中有没有你需要引入的jar包

问题三:本地maven仓库有很多.lastUpdated结尾的文件,这是为什么?

1、可能是jar的坐标有问题,即groupId、artifactId、version拼写有问题;

2、jar包压根就不存在;

3、私服镜像地址有问题;

4、网络问题,比如本地无法使用ipv6网络,需要强制指定ipv4,具体操作请查看这篇文章

由于以上问题,导致jar包无法下载,会在对于的路径下,生成.lastUpdated文件,所以我们需要删除本地仓库.lastUpdated重新下载,要不然会影响再次下载和后续的编译运行。

linux、macos环境下,批量删除

find 私服路径 -name "*lastUpdated*" | xargs rm -rf
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/1010415
推荐阅读
相关标签
  

闽ICP备14008679号