关于maven3:聊聊springboot项目引用第三平台私有jar踩到的坑

前言最近和敌人闲聊,他说他遇到一个问题,他援用了第三方公司公有API包,他在本地我的项目启动没问题,打包运行却找不到这个API包,于是我就问他怎么援用这个jar。 他工程项目第三jar寄存的地位相似如下在pom做如下援用 <dependency> <groupId>org.example</groupId> <artifactId>demo-api</artifactId> <version>1.0-SNAPSHOT</version> <scope>system</scope> <systemPath>${project.basedir}/lib/demo-api.jar</systemPath> </dependency>pom打包插件用springboot自带的插件 <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>看到这个插件,大略就晓得问题所在了,springboot默认的打包插件是不会把systemscope的jar打进springboot我的项目的BOOT-INF/lib/。 注: springboot我的项目默认会援用BOOT-INF/lib/外面的jar 于是我就跟敌人说,不要用systemscope了,间接搭建maven私仓,而后把第三方jar上传到私仓中,pom做如下援用 <dependency> <groupId>org.example</groupId> <artifactId>demo-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency>敌人给回复是公司没有私仓,我一脸懵逼,我就问他应该不至于吧,再次确认,失去他同样的回复后。后边就提供了下边的几种计划,让他参考抉择 springboot如何援用没有公布到私仓的第三jar整体思路:因为springboot提供的打包插件,默认是会把位于BOOT-INF/lib/外面的jar编译成class文件而后供我的项目援用。因而咱们只需确保BOOT-INF/lib/外面含有咱们要援用的第三方jar即可 计划一:pom指定jar范畴为system+springboot插件退出includeSystemScope标签的属性为true示例: <dependency> <groupId>org.example</groupId> <artifactId>demo-api</artifactId> <version>1.0-SNAPSHOT</version> <scope>system</scope> <systemPath>${project.basedir}/lib/demo-api.jar</systemPath> </dependency> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>计划二:pom指定jar范畴为system+resources标签引入要蕴含的jar <dependency> <groupId>org.example</groupId> <artifactId>demo-api</artifactId> <version>1.0-SNAPSHOT</version> <scope>system</scope> <systemPath>${project.basedir}/lib/demo-api.jar</systemPath> </dependency> <build> <resources> <resource> <directory>${project.basedir}/lib</directory> <targetPath>BOOT-INF/lib/</targetPath> <includes> <include>**/*.jar</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>计划三:间接将第三方jar打进要公布的本地仓库上图是maven官网的仓库流程图,其实对maven比拟相熟的敌人应该会晓得,maven会先从本地仓库找jar,本地仓库找不到jar,就会再从私仓(如果有搭建私仓)外面找,私仓没有再从地方仓库找,而后找到的jar再寄存到本地仓库。 ...

June 15, 2021 · 1 min · jiezi

关于maven3:centos7-mvn-上传jar到私服

遇到如下问题 “Failed to transfer file: http://skf-nexus.xxxxx.com/re... Return code is: 401”找一台有maven的机器批改配置[root@dev-technology-215l ~]# cat /usr/local/apache-maven-3.3.9/conf/settings.xml<settings> <mirrors> <!--给定仓库的下载镜像。 --> <mirror> <!--该镜像的惟一标识符。id用来辨别不同的mirror元素。 --> <id>xxxxx</id> <!--镜像名称 --> <name>Nexus xxxxx</name> <!--该镜像的URL。构建零碎会优先思考应用该URL,而非应用默认的服务器URL。 --> <url>http://nexus.xxxxx.com/repository/xxxxx-maven-central/</url> <!--被镜像的服务器的id。例如,如果咱们要设置了一个Maven地方仓库(http://repo1.maven.org/maven2)的镜像,--> <!--就须要将该元素设置成central。这必须和地方仓库的id central完全一致。 --> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile> <profile> <id>dev</id> <repositories> <repository> <id>nexus</id> <url>http://skf-nexus.xxxxx.com/repository/xxxxx-release/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles> <servers> <server> <id>releases</id> <username>admin</username> <password>xxxxx-0312</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>xxxxx-0312</password> </server> </servers> <distributionManagement> <repository> <id>xxxxx-releases</id> <name>Nexus Release Repository</name> <url>http://skf-nexus.xxxxx.com/repository/xxxxx-release/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://skf-nexus.xxxxx.com/repository/snapshots/</url> </snapshotRepository> </distributionManagement></settings>jar 包上传命令mvn deploy:deploy-file -DgroupId=com.csii.pe.http -DartifactId=security -Dversion=1.3 -Dpackaging=jar -Dfile="/tmp/maventest/com-csii-pe-http-security-1.3.jar" -Durl=http://skf-nexus.xxxxx.com/re... -DrepositoryId=releases

October 20, 2020 · 1 min · jiezi