[英]How to remove a maven lib (jsr250-api-1.0.jar) from the plugin classpath (jetty:run)?
I'm working on migrating our projects from java 8 to 11.我正在将我们的项目从 java 8 迁移到 11。
As a first step, i'm compiling it with source and target compatibility 1.8, but trying to run the application over the openjdk-11.作为第一步,我使用源和目标兼容性 1.8 对其进行编译,但尝试在 openjdk-11 上运行应用程序。
During development, we are using the jetty:run goal to start the application server.在开发过程中,我们使用 jetty:run 目标来启动应用程序服务器。 This goal is failing with this error :
此目标因此错误而失败:
Caused by: java.lang.NoSuchMethodError: javax.annotation.Resource.lookup()Ljava/lang/String;
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.<init>(CommonAnnotationBeanPostProcessor.java:621) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.lambda$buildResourceMetadata$0(CommonAnnotationBeanPostProcessor.java:383) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:713) ~[spring-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.buildResourceMetadata(CommonAnnotationBeanPostProcessor.java:365) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.findResourceMetadata(CommonAnnotationBeanPostProcessor.java:350) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:298) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1043) ~[spring-beans-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:550) ~[spring-beans-5.1.0.RELEASE.jar:5.1.0.RELEASE]
... 63 more
Regarding to the Using Extensions and Core Classloader , we are able to override the ${maven.home}/lib
by defining the extensions
at our pom.xml
as the following: - 关于Using Extensions和Core Classloader ,我们可以通过在
pom.xml
定义extensions
来覆盖${maven.home}/lib
,如下所示: -
<build>
<extensions>
<extension>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</extension>
<extension>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</extension>
</extensions>
</build>
When executing the mvn -e -X clean test
, it give us the following: - 执行
mvn -e -X clean test
,它给出了以下内容: -
[DEBUG] javax.annotation:javax.annotation-api:jar:1.3.2:
[DEBUG] org.codehaus.plexus:plexus-utils:jar:1.1:runtime
[DEBUG] Created new class realm extension>
javax.annotation:javax.annotation-api:1.3.2
[DEBUG] Importing foreign packages into class realm extension>
javax.annotation:javax.annotation-api:1.3.2
[DEBUG] Imported: < maven.api
[DEBUG] Populating class realm extension>
javax.annotation:javax.annotation-api:1.3.2
[DEBUG] Included: javax.annotation:javax.annotation-api:jar:1.3.2
[DEBUG] Included: org.codehaus.plexus:plexus-utils:jar:1.1
[DEBUG] Dependency collection stats: {...}
[DEBUG] javax.annotation:jsr250-api:jar:1.0:
[DEBUG] org.codehaus.plexus:plexus-utils:jar:1.1:runtime
[DEBUG] Created new class realm extension>
javax.annotation:jsr250-api:1.0
[DEBUG] Importing foreign packages into class realm extension>
javax.annotation:jsr250-api:1.0
[DEBUG] Imported: < maven.api
[DEBUG] Populating class realm extension>
javax.annotation:jsr250-api:1.0
....
[DEBUG] Extension realms for project some-group:some-artifact:some-packing:some-version :
[ClassRealm[extension>javax.annotation:javax.annotation-api:1.3.2,
parent: sun.misc.Launcher$AppClassLoader@5c647e05],
ClassRealm[extension>javax.annotation:jsr250-api:1.0,
parent: sun.misc.Launcher$AppClassLoader@5c647e05]]
[DEBUG] Created new class realm project>some-group:some-artifact:some-version
[DEBUG] Populating class realm project>some-group:some-artifact:some-version
[DEBUG] Included: javax.annotation:javax.annotation-api:jar:1.3.2
[DEBUG] Looking up lifecycle mappings for packaging war from
ClassRealm[project>some-group:some-artifact:some-version,
parent: ClassRealm[maven.api, parent: null]]
I cannot get rid of the javax.annotation:jsr250-api:1.0
, then I put it after the javax.annotation:javax.annotation-api:1.3.2
so that it will be far from the classpath and ensure that the javax.annotation:javax.annotation-api:1.3.2
will be used first. 我无法摆脱
javax.annotation:jsr250-api:1.0
,然后我把它放在javax.annotation:javax.annotation-api:1.3.2
,它将远离类路径并确保javax.annotation:javax.annotation-api:1.3.2
首先使用javax.annotation:javax.annotation-api:1.3.2
。
请注意,这不再是 Maven 3.8.3+ 的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.