如何解决EclipseLink 3.x编译时SecurityException签名信息不匹配问题?
Maven编译EclipseLink 3.0.x实体JAR失败的解决方案
我之前也碰到过完全一样的问题,在Java EE项目的实体JAR上执行mvn install时,maven-compiler-plugin 3.7.0直接抛出了致命编译错误,折腾了好久才找到根源。
先把报错信息贴出来方便大家对照:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project project1-jar: Fatal error compiling: java.lang.RuntimeException: Exception [EclipseLink-0] (Eclipse Persistence Services - 3.0.0.v20171222-5074888): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:Exception [EclipseLink-86] (Eclipse Persistence Services - 3.0.0.v20171222-5074888): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The instance variable [persistenceUnitName] in the class [org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo] is not accessible.
Internal Exception: java.lang.SecurityException: class "javax.persistence.SharedCacheMode"'s signer information does not match signer information of other classes in the same package
Mapping: org.eclipse.persistence.oxm.mappings.XMLDirectMapping[persistenceUnitName-->@name]
Descriptor: XMLDescriptor(org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo --> [])
Runtime Exceptions:java.lang.NullPointerException -> [Help 1]
问题根源
这是EclipseLink 3.0.x版本的一个已知Bug,核心原因是JPA API类的签名信息和EclipseLink内部类的签名不匹配,触发了类加载时的安全校验失败。而且你提到用EclipseLink <=2.6.x时编译正常,这也完全符合这个版本兼容性问题的特征。
可行的解决方案
- 回退到稳定版本(最推荐):直接把EclipseLink版本降到2.6.x系列(比如2.6.9),这个版本在Java EE环境下经过充分验证,不会出现这种签名冲突问题。修改
pom.xml里的依赖配置就行:<dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId> <version>2.6.9</version> <scope>provided</scope> <!-- 根据你的项目实际需求调整scope --> </dependency> - 排查并解决依赖冲突:如果一定要用3.x版本,就仔细检查项目的依赖树,看看是不是有其他依赖引入了不同版本的JPA API(比如
javax.persistence-api或者jakarta.persistence-api)。可以用mvn dependency:tree命令生成依赖树报告,然后排除掉冲突的依赖,确保整个项目里只保留EclipseLink自带的JPA API版本。 - 等待官方修复:虽然你提交的Bug报告目前还没收到反馈,但可以持续关注该Bug的处理状态,等官方发布修复版本后再尝试升级到3.x系列。
内容的提问来源于stack exchange,提问作者Kalle Richter
相关产品推荐
相关产品推荐

