Jenkins执行Maven项目的离线构建,引用本地lib资源方案记录

这篇具有很好参考价值的文章主要介绍了Jenkins执行Maven项目的离线构建,引用本地lib资源方案记录。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

背景

这段时间手头上有个多模态结构的Maven项目需要给到客户进行验证部署,且不能直接打包镜像,而是在客户本地进行编译构建,但由于客户方的 Maven 私库有网络隔离不能连通外网,我们无法将项目的其他依赖推送到客户方,所以就需要将项目适配成引用本地lib目录下的jar包。

期间参考了网上通用的引用本地lib资源,但在本地执行mvn package 指令打包出来的运行jar包是可以正常运行,但最终提交到 Jenkins 构建计划的时候,则一直无法将 lib 下的 jar 包资源拷贝到服务jar中。

反复挣扎了许久之后,最终还是请教了架构大佬获得了解救方案。

普通引用方案

项目改造过程期间,参考了网上的博客或相关案例(eg:https://blog.csdn.net/qq_49139682/article/details/127216805),基本上步骤可以总结如下:

  1. 执行 mvn 指令将项目的所有依赖导出来

mvn dependency:copy-dependencies -DoutputDirectory=lib
  1. 项目引用的依赖调整,设置为引用lib目录下的jar:

   <dependencies>
        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.26</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/../lib/lombok-1.18.26.jar</systemPath>
        </dependency>
    </dependencies>
  1. 增加 spring-boot-maven-plugin ,并配置includeSystemScope属性为 true

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                <!--设置为true,以便把本地的system的jar也包括进来-->
                    <includeSystemScope>true</includeSystemScope>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
  1. 增加 maven-compiler-plugin ,并配置编译时,引用项目的lib目录

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <extdirs>${project.basedir}/lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
  1. 增加 maven-source-plugin 插件


                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.2.1</version>
                    <!-- 绑定source插件到Maven的生命周期,并在生命周期后执行绑定的source的goal -->
                    <executions>
                        <execution>
                            <!-- 绑定source插件到Maven的生命周期 -->
                            <phase>deploy</phase>
                            <!--在生命周期后执行绑定的source插件的goals -->
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

最终在本地验证的时候,执行package指令是可以打包成功的,当时便一度以为问题已解决,但结果上流水线构建的时候,就发现了新的问题:

流水线里面执行了copy lib资源到服务jar中,但实际去查看最终的结果jar里的/BOOT-INF/lib 目录下,却没有找到任何需要拷贝进去的lib资源。

maven lib,spring boot,java,maven,jenkins,Powered by 金山文档

这个问题排查了很久,奈何自己水平实在是过于辣鸡,一直都没有定位出来。最终还是将问题升级到大佬协助定位。

最终方案

  1. 复制依赖包到lib目录

  • 在项目的parent#pom.xml下增加maven-dependency-plugin配置

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <configuration>
                    <outputDirectory>${pom.basedir}/../lib</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
  • 然后执行maven命令clean package,执行完成后会在生成lib目录,这些为此项目所需的依赖jar包

maven lib,spring boot,java,maven,jenkins,Powered by 金山文档
  1. 修改项目配置为离线依赖

  • 修改项目的各module#pom.xml的build配置,如 [lib-package-sample-api-dto/pom.xml]、 [lib-package-sample-service/pom.xml]、 [lib-package-sample-web/pom.xml]

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <goals/>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <extdirs>${pom.basedir}/../lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
maven lib,spring boot,java,maven,jenkins,Powered by 金山文档
  • 修改项目的各module#pom.xml的dependencies配置,如 [lib-package-sample-api-dto/pom.xml]、 [lib-package-sample-service/pom.xml]、 [lib-package-sample-web/pom.xml]

    <dependencies>
        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.26</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/../lib/lombok-1.18.26.jar</systemPath>
        </dependency>
    </dependencies>
maven lib,spring boot,java,maven,jenkins,Powered by 金山文档
  • 移除项目中父级pom.xml中关于其他pom依赖的引入,如项目中还要依赖一个自定义的框架pom,因为本地引用无法导出非jar包形式的文件。

maven lib,spring boot,java,maven,jenkins,Powered by 金山文档
  • 修改项目的web服务#pom.xml的spring-boot-maven-plugin插件配置,增加 <layout>ZIP</layout>,如 [lib-sample-single-web/pom.xml]

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
maven lib,spring boot,java,maven,jenkins,Powered by 金山文档
  1. 离线打包及启动

3.1. 使用maven命令 clean install -DskipTests 打包,生成的jar,此时的jar内不含依赖包,故启动时需要指定依赖包。

java -jar -Dloader.path=lib  lib-package-sample-web.jar

jar包及lib包的位置如下:

maven lib,spring boot,java,maven,jenkins,Powered by 金山文档
  1. 原项目其他问题及解决方案

4.1. Could not find resource [application.properties]

  • 如果项目中使用了logback打印框架,启动时,logback-spring.xml 读取application.properties配置失败,原因是加载顺序先后导致,可将配置项移除。

LOGBACK: No context given for org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender[null]
2023-03-02T11:42:46.049+08:00 [ERROR][lib-sample-single-web][107292][][main][] --- org.springframework.boot.SpringApplication-845 : Application run failed 
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.action.PropertyAction - Could not find resource [application.properties].
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:82)
    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:117)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:264)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:237)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
    at com.lls.lib.sample.single.web.LibSampleSingleWebApp.main(LibSampleSingleWebApp.java:29)
exception:Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.action.PropertyAction - Could not find resource [application.properties].
end2023-03-02T11:42:46.056
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.action.PropertyAction - Could not find resource [application.properties].
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:82)
    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:117)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:264)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:237)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
    at com.lls.lib.sample.single.web.LibSampleSingleWebApp.main(LibSampleSingleWebApp.java:29)
Disconnected from the target VM, address: '127.0.0.1:63167', transport: 'socket'

Process finished with exit code 0

maven lib,spring boot,java,maven,jenkins,Powered by 金山文档

4.2. com.alibaba.druid.pool.DruidDataSource-974 : {dataSource-1} init error

  • 启动时,数据库密码解密失败,暂时不明原因,可先将数据库密码(spring.datasource.password配置项)改为明文。

2023-03-02T18:47:58.790+08:00 [INFO ][lib-sample-single-web][116936][][localhost-startStop-1][] --- com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure-56 : Init DruidDataSource
2023-03-02T18:47:59.033+08:00 [ERROR][lib-sample-single-web][116936][][localhost-startStop-1][] --- com.alibaba.druid.pool.DruidDataSource-974 : {dataSource-1} init error
java.lang.IllegalArgumentException: Failed to decrypt.
        at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:205)
        at com.alibaba.druid.filter.config.ConfigFilter.init(ConfigFilter.java:123)
        at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:839)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1824)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1767)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1322)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1288)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1215)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1093)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getIfAvailable(DefaultListableBeanFactory.java:1706)
        at org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration.<init>(DataSourceHealthIndicatorAutoConfiguration.java:77)
        at org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$b8a1394b.<init>(<generated>)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:170)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:275)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:514)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:502)
        at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1198)
        at org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorBeansComposite.get(HealthIndicatorBeansComposite.java:46)
        at org.springframework.boot.actuate.autoconfigure.health.HealthEndpointConfiguration.healthEndpoint(HealthEndpointConfiguration.java:38)
        at org.springframework.boot.actuate.autoconfigure.health.HealthEndpointConfiguration$$EnhancerBySpringCGLIB$$665d9da8.CGLIB$healthEndpoint$0(<generated>)
        at org.springframework.boot.actuate.autoconfigure.health.HealthEndpointConfiguration$$EnhancerBySpringCGLIB$$665d9da8$$FastClassBySpringCGLIB$$d822f5cc.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
        at org.springframework.boot.actuate.autoconfigure.health.HealthEndpointConfiguration$$EnhancerBySpringCGLIB$$665d9da8.healthEndpoint(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089)
        at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.createEndpointBean(EndpointDiscoverer.java:143)
        at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.createEndpointBeans(EndpointDiscoverer.java:132)
        at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.discoverEndpoints(EndpointDiscoverer.java:122)
        at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.getEndpoints(EndpointDiscoverer.java:116)
        at org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.servletEndpointRegistrar(ServletEndpointManagementContextConfiguration.java:75)
        at org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration$$EnhancerBySpringCGLIB$$fff13fa0.CGLIB$servletEndpointRegistrar$0(<generated>)
        at org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration$$EnhancerBySpringCGLIB$$fff13fa0$$FastClassBySpringCGLIB$$225f74d0.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
        at org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration$$EnhancerBySpringCGLIB$$fff13fa0.servletEndpointRegistrar(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:226)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:214)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:91)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:80)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:250)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:237)
        at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1421)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1411)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA/ECB/PKCS1Padding
        at javax.crypto.Cipher.getInstance(Cipher.java:543)
        at com.alibaba.druid.filter.config.ConfigTools.decrypt(ConfigTools.java:133)
        at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:197)
        ... 111 common frames omitted

4.3. 密文加解密失败

  • 解决方案:Java指令-Djava.ext.dirs的陷阱_cyony的博客-CSDN博客

这两天由于现场需求,需要把ES索引写入插件改造成带安全认证的方式,加密算法是由java.security相关类实现的。在DEMO中测试了若干次都没问题,但是放到生成环境中就是报NoSuchAlgorithmException的错误,相关错误如下:

这个问题困扰了好久,经过多方面的排查,其中细节不一一描述,最终发现是生产环境下的启动指令属性-Djava.ext.dirs出现了问题。
-Djava.ext.dirs会覆盖Java本身的ext设置,java.ext.dirs指定的目录由ExtClassLoader加载器加载,
如果您的程序没有指定该系统属性,那么该加载器默认加载$JAVA_HOME/jre/lib/ext目录下的所有jar文件。
但如果你手动指定系统属性且忘了把$JAVA_HOME/jre/lib/ext路径给加上,那么ExtClassLoader不会去加载$JAVA_HOME/lib/ext下面的jar文件,
这意味着你将失去一些功能,例如java自带的加解密算法实现。

OK问题分析到这儿,什么原因已经很明朗,解决方案也很简单,只需在改路径后面补上ext的路径即可!比如:
-Djava.ext.dirs=./plugin:$JAVA_HOME/jre/lib/ext。windows环境下运行程序,应该用分号替代冒号来分隔。

4.4. springboot 引用外部jar启动

  • java - Spring Boot Executable Jar with Classpath - Stack Overflow文章来源地址https://www.toymoban.com/news/detail-762774.html

到了这里,关于Jenkins执行Maven项目的离线构建,引用本地lib资源方案记录的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 使用Jenkins构建发布一个简单的maven项目

    上一章,完成了jenkins在ubuntu上的安装,这一章将使用单个Jenkins服务完成一个maven项目的打包和发布。 用到的插件有:Maven Integration、Git、Publish Over SSH三个,在Dashboard - Manage Jenkins - Plugins -Available plugins里搜索并安装。 2.1、配置好JDK 在Dashboard - Manage Jenkins - Tools里将JAVA_HOME的目

    2024年02月16日
    浏览(42)
  • OpenAI的离线音频转文本模型 Whisper 的.NET封装项目

    whisper介绍 Open AI在2022年9月21日开源了号称其英文语音辨识能力已达到人类水准的Whisper神经网络,且它亦支持其它98种语言的自动语音辨识。 Whisper系统所提供的自动语音辨识(Automatic Speech Recognition,ASR)模型是被训练来运行语音辨识与翻译任务的,它们能将各种语言的语音变

    2023年04月24日
    浏览(40)
  • jenkins 2.346.1 从git拉取后自动构建部署springboot maven项目

    1、jenkins官网下载 jenkins2.346.1版本(2.346之后不支持java8) Jenkins 的安装和设置 下载的war包通过 java -jar jenkins.war可运行 也可下载安装版本直接安装 http://localhost:8080,端口号8080根据安装时的设定进行对应的变更,安装后需要等待一段时间。 确认发布应用的服务器安装了java g

    2024年02月02日
    浏览(50)
  • linux jenkins 2.89.1 安装部署 持续构建svn下maven项目并部署到tomcat

    从这边博文可以学习到:  jenkins的安装 修改主目录 初始化 新建任务,构建第一个maven项目 将构建完成的项目部署到tomcat Jenkins的安装相当简单,只需要从官网下载war包,放入tomcat,运行tomcat就可以访问Jenkins了 准备工作:安装java环境,一个tomcat7+。如果构建maven项目还需要安

    2024年02月20日
    浏览(42)
  • Python的离线安装

    原文链接 在没有外网的情况下,安装Python环境只能采用离线方式。 Python离线安装包的下载地址:https://www.python.org/ftp/python/ 我选择的是: python-3.8.5-amd64.exe 双击运行安装包即可完成安装。 安装完成后添加环境变量: 查看是否成功: 输出版本号 Python 3.8.5 即表示安装成功。

    2024年02月08日
    浏览(61)
  • IntelliJ IDEA maven 引用本地 jar 文件

    一、背景说明 由于某些特定原因,不能在远程maven仓库中下载所需要版本的jar文件,需要在maven中引用本地jar文件。 二、解决方案 1、创建 libs 目录 为了方便jar包管理,可以在工程目录下,创建一个与src目录平级的libs目录。如下: 2、工程模块引入依赖 1)File -- Project Struct

    2024年02月11日
    浏览(45)
  • Maven引用本地jar包以及打包发布注意事项

    1、Maven引用本地jar包 首先在resources目录下创建名为【lib】的文件夹,然后将本地jar包放入该文件夹下,如图  然后在pom文件中引用该jar包 2、maven编译时找不到本地引用的jar包 在maven编译完成后,运行jar包的时候报错找不到本地引用的jar包,需要在pom文件中build中的【spring-b

    2023年04月09日
    浏览(102)
  • 浅述HTML5的离线存储

    离线存储是什么?  离线存储就是在用户没有与因特网连接时,可以正常访问站点或应用,在用户与因特网连接时,更新用户机器上的缓存文件。 离线存储的原理: h5的离线存储是基于一个新建的.appcache文件的缓存机制,通过这个文件上的解析清单离线存储资源,这些资源就

    2024年04月10日
    浏览(45)
  • 制作vs2017的离线安装包

    在公司的电脑上安装了vs2015,但是30天体验卡到期之后不能离线激活,所以只能下个vs2017。可微软官网vs2017的社区版停了,另外说一下官网有版本也都是在线的下载器。又由于公司的电脑不能连外网的,所以在安装vs的时候就只能使用安装包。所以只能用一天的时间自己鼓捣了

    2024年02月08日
    浏览(85)
  • vue前端项目引用高德离线地图

    由于上一篇下载离线地图瓦片的工具有问题,需要更换工具重新下载离线瓦片,步骤如下: 1.1用MapDownloader,下载离线地图瓦片 工具提取码: mmdl 需要对工具作如下配置 : MapDownloader.exe.config 文件进行修改 保存之后运行 MapDownloader.exe文件 1.2 选择mysql数据库,然后选择要下载得地

    2024年02月08日
    浏览(59)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包