(转)通过maven,给没有pom文件的jar包生成pom文件,maven项目引入本地jar包

时间:2022-12-12 16:31:38

文章完全转载自 : https://blog.csdn.net/qq_31289187/article/details/81117478

问题一:

经常遇到公司私服或者*仓库没有的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包目录下以下结果
(转)通过maven,给没有pom文件的jar包生成pom文件,maven项目引入本地jar包

问题二:

自己本地的jar包,公司私服上没有,引入本地的jar包,现在项目的resource目录下新建lib文件夹,然后将你本地的jar包copy到里面

(转)通过maven,给没有pom文件的jar包生成pom文件,maven项目引入本地jar包

在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包

(转)通过maven,给没有pom文件的jar包生成pom文件,maven项目引入本地jar包