求助:IDE外运行Shadow Jar出现ALPN Processor未找到错误
Shadow Jar运行时报错No ALPN Processor的解决方法
问题详情
在IntelliJ IDE中直接运行主类时项目正常,但打包成Shadow Jar后在IDE外运行抛出ALPN处理器相关错误,具体报错:
[etp239465106-49] WARN org.eclipse.jetty.io.ManagedSelector - Could not accept java.nio.channels.SocketChannel[closed]: java.lang.IllegalStateException: Connection rejected: No ALPN Processor for sun.security.ssl.SSLEngineImpl from [org.eclipse.jetty.alpn.conscrypt.server.ConscryptServerALPNProcessor@3af94f7b]
项目Gradle配置如下:
plugins { id 'java' id "com.github.johnrengelman.shadow" version "8.1.1" } group = 'me.alex' version = '1.0-SNAPSHOT' repositories { mavenCentral() maven { url 'https://jitpack.io' } } dependencies { implementation ('com.github.GoldenGamerLP:DependencyLoader:eed2460e41') { exclude module: 'DependencyExamples' } annotationProcessor('com.github.GoldenGamerLP:DependencyLoader:eed2460e41') { exclude module: 'DependencyExamples' } implementation 'org.slf4j:slf4j-simple:2.0.7' //Javalin implementation 'io.javalin:javalin:5.6.2' implementation 'com.github.HttpMarco:Aeon:-SNAPSHOT' //JsonParser implementation 'com.google.code.gson:gson:2.8.8' //Lombok implementation 'org.projectlombok:lombok:1.18.28' annotationProcessor 'org.projectlombok:lombok:1.18.28' //OpenAPI compileOnly 'io.javalin.community.openapi:javalin-openapi-plugin:5.6.2' implementation 'io.javalin.community.ssl:ssl-plugin:5.6.2' implementation ('org.eclipse.jetty:jetty-nosql:11.0.15') { exclude group: 'org.mongodb' } compileOnly 'org.mongodb:mongodb-driver-sync:4.6.0' } //Manifest jar { manifest { attributes( 'Main-Class': 'me.alex.app.street14endpoint.EndpointBootstrap', 'Multi-Release': true ) } }
已尝试构建各类Fat Jar、赋予Jar权限、重构代码、咨询技术人员、提交插件Issue等方法,均未解决问题。
核心原因
报错本质是Java SPI服务文件在Shadow打包时未被正确合并:Jetty的ALPN处理器通过SPI机制加载,而Shadow插件默认不会合并META-INF/services目录下的同名文件,导致运行时找不到可用的ALPN处理器实现。此外,Conscrypt作为ALPN的实现依赖,可能在打包过程中存在类加载或依赖缺失问题。
解决方案
1. 配置Shadow插件合并SPI服务文件
修改build.gradle,添加Shadow插件的服务文件合并配置,替换原有的jar块配置(Shadow插件的shadowJar任务才是生成最终Fat Jar的核心任务):
shadowJar { mergeServiceFiles() // 合并所有META-INF/services目录下的SPI服务文件 manifest { attributes( 'Main-Class': 'me.alex.app.street14endpoint.EndpointBootstrap', 'Multi-Release': true ) } }
2. 确保Conscrypt依赖完整引入
报错中提到ConscryptServerALPNProcessor,需确认Conscrypt相关依赖被正确包含进Shadow Jar。若依赖链未自动引入,可显式添加:
dependencies { // 保留原有依赖,新增以下两行 implementation 'org.eclipse.jetty:jetty-alpn-conscrypt-server:11.0.15' implementation 'org.conscrypt:conscrypt-openjdk-uber:2.5.2' }
版本号需与项目中Jetty版本(11.0.15)匹配,避免版本冲突。
3. 适配JDK版本调整依赖
- JDK 8:依赖Conscrypt提供ALPN支持,确保上述Conscrypt依赖正确引入即可,无需额外JVM参数。
- JDK 9+:JDK内置ALPN支持,可尝试替换Conscrypt为Jetty的Java内置ALPN实现,避免冲突:
dependencies { implementation ('io.javalin.community.ssl:ssl-plugin:5.6.2') { exclude group: 'org.eclipse.jetty', module: 'jetty-alpn-conscrypt-server' } implementation 'org.eclipse.jetty:jetty-alpn-java-server:11.0.15' }
4. 验证Shadow Jar内容
打包完成后,执行命令jar tf your-shadow-jar.jar检查Jar内容:
- 确认
META-INF/services/org.eclipse.jetty.alpn.server.ALPNProcessor文件存在,且包含对应ALPN处理器类名(如org.eclipse.jetty.alpn.conscrypt.server.ConscryptServerALPNProcessor)。 - 确认Conscrypt相关类(
org.conscrypt.*)或Java ALPN相关类存在于Jar中。
内容的提问来源于stack exchange,提问作者Alexander
相关产品推荐
相关产品推荐

