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 ...
随机推荐
- ORACLE-创建用户和表空间
/*分为四步 *//*第1步:创建临时表空间 */create temporary tablespace user_temp tempfile 'D:\oracle\oradata\Oracle9i\ ...
- Spring Boot 学习-基础
一.Spring Boot 概述 SpringBoot 定义 Spring Boot 并不是用来替代 Spring 的新框架,而是和 Spring 框架紧密结合用于提升 Spring 开发者体验的工具 ...
- C#早期绑定&后期绑定
早期绑定(early binding),又可以称为静态绑定(static binding).在使用某个程序集前,已知该程序集里封装的方法.属性等.则创建该类的实例后可以直接调用类中封装的方法. 后期绑 ...
- Qt:QJsonParseError
0.说明 QJsonParseError用于JSON解析时报告error. 1.模块和加载项 Header #include<QJsonParseError> qmake QT += co ...
- 让Node.js支持ES6的语法
使用命令,全局安装es-checker: cnpm install -g es-checker 安装好之后,执行以下命令来查看Node.js对ES6的支持情况. es-checker 可以从输出中查看 ...
- pandas模块篇(终章)及初识mataplotlib
今日内容概要 时间序列 针对表格数据的分组与聚合操作 其他函数补充(apply) 练习题(为了加深对DataFrame操作的印象) mataplotlib画图模块 今日内容详细 时间序列处理 时间序列 ...
- JAVA——转义字符
目录 1.Java转义字符 2.Java中的注释 2.1Java 中的注释类型 2.2文档注释 3.Java代码规范 4.Java开发注意事项和细节说明 1.Java转义字符 在控制台,输入 tab ...
- 矩池云 | 高性价比的GPU租用深度学习平台
矩池云是一个专业的国内深度学习云平台,拥有着良好的深度学习云端训练体验.在性价比上,我们以 2080Ti 单卡为例,36 小时折扣后的价格才 55 元,每小时单价仅 1.52 元,属于全网最低价.用户 ...
- 微信小程序知识点汇总
微信小程序常用标签与HTML的对应关系 <div></div> <view></view> <h1></h1>...<h6 ...
- php 23种设计模式 - 设计模式简介以及分类
一. Introduction[介绍] 设计模式:提供了一种广泛的可重用的方式来解决我们日常编程中常常遇见的问题.设计模式并不一定就是一个类库或者第三方框架,它们更多的表现为一种思想并且广泛地应用在系 ...