springboot服务引入外部jar包在windows运行正常,在linux环境上无法加载到引入jar包的类
一、问题描述
最近开发了一个springboot程序,需要依赖第三方jar包,这个jar包无法直接通过pom远程仓库下载,需要从自己本地引入,于是配置pom文件如下:将本地jar包引入工程,systemPath为jar所在的本地路径
<!--第三方jar包引入-->
<dependency>
<groupId>com.hikvision.js</groupId>
<artifactId>data-sdk-bms</artifactId>
<version>2.0.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/data-sdk-bms-2.0.3.jar</systemPath>
</dependency>
在打包时将本地引入的jar引入打进lib文件夹下,如果没有如下配置,jar无法打入lib目录
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
<scope>system</scope>
</dependencySet>
</dependencySets>
然后使用maven打包,首先部署到windows机器上,启动程序,运行正常,然后将程序部署到linux环境上,运行报如下错误:
[WARN ] [2020-09-09 09:28:15] [org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.hikvision.js.deployalarmtool.DeployalarmtoolApplication]; nested exception is java.io.FileNotFoundException: class path resource [com/hikvision/bms/caller/BmsMessage.class] cannot be opened because it does not exist
[ERROR] [2020-09-09 09:28:15] [org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:771)] Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.hikvision.js.deployalarmtool.DeployalarmtoolApplication]; nested exception is java.io.FileNotFoundException: class path resource [com/hikvision/bms/caller/BmsMessage.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:183)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.hikvision.js.deployalarmtool.DeployalarmtoolApplication.main(DeployalarmtoolApplication.java:14)
Caused by: java.io.FileNotFoundException: class path resource [com/hikvision/bms/caller/BmsMessage.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:50)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:102)
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:89)
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:76)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:701)
at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getInterfaces(ConfigurationClassParser.java:879)
at org.springframework.context.annotation.ConfigurationClassParser.processInterfaces(ConfigurationClassParser.java:368)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:325)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:247)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:297)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:247)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:200)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:169)
... 13 more
nested exception is java.io.FileNotFoundException: class path resource [com/hikvision/bms/caller/BmsMessage.class] cannot be opened because it does not exist,显然是com/hikvision/bms/caller/BmsMessage.class这个类不存在,而这个类正是引入的本地的那个jar包中的,检查lib目录发现jar是存在的,并且权限也正常,这就很奇怪,一时间束手无策。
排查无果,又重新打包,发现一个maven的warning日志:
[WARNING] 'dependencies.dependency.systemPath' for com.hikvision.js:data-sdk-bms:jar should not point at files within the project directory, ${project.basedir}/lib/data-sdk-bms-2.0.3.jar will be unresolvable by dependent projects @ line 113, column 25
于是我便从这个warning入手进行排查,果然warning解决,问题也得到了解决。
二、解决方法
本地第三方jar包引入方法:
<!--第三方jar包引入-->
<dependency>
<groupId>com.hikvision.js</groupId>
<artifactId>data-sdk-bms</artifactId>
<version>2.0.3</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-data-sdk-bms</id>
<phase>clean</phase>
<configuration>
<file>${project.basedir}/lib/data-sdk-bms-2.0.3.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>com.hikvision.js</groupId>
<artifactId>data-sdk-bms</artifactId>
<version>2.0.3</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
按上面的方式配置pom,打包正常,windows和linux环境下运行也正常。
springboot服务引入外部jar包在windows运行正常,在linux环境上无法加载到引入jar包的类的更多相关文章
- 页面引入外部字体ttf,如何提取所需要的ttf字体或者加载过慢的解决方法-1127更新
最近几天编写手机端的页面之后,文中需要华文行楷字体,在网上下载后,引入到了自己的前端页面,以为没有什么事了,继续码代码 @font-face { font-family:huawen; src: ur ...
- SpringBoot在启动时的多环境配置以及加载顺序
通常我们在开发完成一个SpringBoot项目时,总是要打包部署的. 在启动SpringBoot应用时,我们常常会使用命令java -jar xxx.jar来启动这个服务. 命令java -jar 除 ...
- Java ClassLoader基础及加载不同依赖 Jar 中的公共类
转载自:最新内容及最清晰格式请见 http://www.trinea.cn/android/java-loader-common-class/ 本文主要介绍 ClassLoader 的基础知识,Cla ...
- 背水一战 Windows 10 (64) - 控件(WebView): 加载指定 HttpMethod 的请求, 自定义请求的 http header, app 与 js 的交互
[源码下载] 背水一战 Windows 10 (64) - 控件(WebView): 加载指定 HttpMethod 的请求, 自定义请求的 http header, app 与 js 的交互 作者: ...
- Maven编译的时候加载本地路径jar
大家都知道Maven的依赖是通过pom文件管理的,只要配置了<dependency>,Maven就会从本地仓库 -> 远程仓库 -> 中央仓库获取依赖的jar. 但是如果仓库中 ...
- 重新想象 Windows 8 Store Apps (54) - 绑定: 增量方式加载数据
[源码下载] 重新想象 Windows 8 Store Apps (54) - 绑定: 增量方式加载数据 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 绑定 通过实 ...
- 未能正确加载“visual C++ package”包
早上打开360要卸载软件,跳出说系统修复,习惯性的点击修复,结果修复后发现打开vs2012提示“未能正确加载“visual C++ package”包……..”, 重启也一样,google了下,是因为 ...
- 在运行jar时自动加载指定的jar包
初学Java的人经常遇到的一个问题是:如果一个程序依赖某个文件夹下的一堆jar包,那么启动它的时候就需要在java -cp参数后面一个一个的加上jar包的名称,很不方便. 比如主程序类叫Main,在目 ...
- 加载依赖的jar包在命令行编译和运行java文件
在命令里编译和执行java文件,当应用程序需要需要依赖的jar包里面的class文件才能编译运行的时候,应该这样做: 1. 首先是编译过程,在命令行里面执行: (1) javac -classpath ...
随机推荐
- Spring-servlet随笔1
一:工程思想 1.建立父工程 2:导入通用依赖 3:删除无用文件 4:创建不同模块. pom.xml 依赖文件: <dependencies> <dependency> ...
- jmeter & 性能测试:从0到实战(实操易用、面试造火箭、升职加薪必备)
[性能基础] 性能测试概念.术语:https://www.cnblogs.com/uncleyong/p/10706519.html 性能测试流程(新):https://www.cnblogs.com ...
- [旧][Android] ButterKnifeProcessor 工作流程分析
备注 原发表于2016.05.21,资料已过时,仅作备份,谨慎参考 前言 在 [Android] ButterKnife 浅析 中,我们了解了 ButterKnife 的用法,比较简单. 本次文章我们 ...
- RFC3918组播组容量测试——网络测试仪实操
一.简介 1.RFC3918简介 历史 · 在1999年3月成为正式标准 功能 · 评测网络互连设备或网络系统的性能 · 网络设备: 交换机,路由器- 内容 · 定义了一整套测试方法,为不同厂家的设备 ...
- 厌倦了excel绘制地图的繁琐操作,来看看这款可视化地图神器!
在现代生活中,地图无论对于社会主义建设.国防.运输以至旅行都是不可缺少的.要学会正确地使用地图,必须学会如何绘制地图. 最近我发现了一款好用的可视化地图神器,比excel做地图可视化好一万倍!其实呢, ...
- Vue2/3 项目中的 ESLint + Prettier 代码检测格式化风格指南
Vue2/3 项目中的 ESLint + Prettier 代码检测格式化风格指南 因为平时都是使用 VSCode ESLint + Prettier 检测格式化不规范代码,但是随着接手的项目越来越多 ...
- linux目录跳转的好武器z.sh
转至:https://blog.csdn.net/molaifeng/article/details/14123123 中午刷微博时看到一篇有关z.sh的介绍. 众所周知,在linux系统中进入目录都 ...
- CentOS 7 下如何进行Python3的独立安装
一.部署准备工作 部署环境工具检查及安装 1)安装epel-release库,以防db4-devel依赖安装失败 1 yum -y install epel-release 2)安装外部函数库(lib ...
- Ansible安装及初始化-从零到无
--时间:2019年1月12日 --作者:飞翔的小胖猪 前言 说明 文档指导读者在Redhat系列操作系统上安装Ansible软件及初始化配置,包括服务端及被控端的配置文件设置. 以下所有操作都在An ...
- JavaWeb-前端基础
前端基础 前端:我们网站的页面,包括网站的样式.图片.视频等一切用户可见的内容都是前端的内容. 后端:处理网站的所有数据来源,比如我们之前从数据库中查询数据,而我们查询的数据经过处理最终会被展示到前端 ...