【问题标题】:java.lang.NoClassDefFoundError: Could not initialize class com.google.inject.internal.cglib.core.$ReflectUtilsjava.lang.NoClassDefFoundError:无法初始化类 com.google.inject.internal.cglib.core.$ReflectUtils
【发布时间】:2022-01-21 14:48:06
【问题描述】:

我正在尝试在 Jenkins 从机上运行 Selenium 脚本。由于一些漏洞,我无法使用 Java 1.8。我在从属代理上安装了 JDK 9.0.4,但是在尝试从 Jenkins 运行脚本时,出现以下异常

设置:
詹金斯 2.303.3
Java 版本:9.0.4

using settings config with name settings.xml
08:34:04 Replacing all maven server entries not found in credentials list is true
08:34:05 ERROR: Failed to parse POMs
08:34:05 java.io.IOException: Remote call on JNLP4-connect connection from VSXXXJENKINS16QA.FLEET.AD/XXXXXXfailed
08:34:05    at hudson.remoting.Channel.call(Channel.java:1005)
08:34:05    at hudson.FilePath.act(FilePath.java:1166)
08:34:05    at hudson.FilePath.act(FilePath.java:1155)
08:34:05    at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.parsePoms(MavenModuleSetBuild.java:985)
08:34:05    at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:689)
08:34:05    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:514)
08:34:05    at hudson.model.Run.execute(Run.java:1888)
08:34:05    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
08:34:05    at hudson.model.ResourceController.execute(ResourceController.java:99)
08:34:05    at hudson.model.Executor.run(Executor.java:431)
08:34:05 Caused by: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: Could not initialize class com.google.inject.internal.cglib.core.$ReflectUtils
08:34:05    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2232)
08:34:05    at com.google.common.cache.LocalCache.get(LocalCache.java:3965)
08:34:05    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3969)
08:34:05    at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4829)
08:34:05    at com.google.common.cache.LocalCache$LocalManualCache.getUnchecked(LocalCache.java:4834)
08:34:05    at com.google.inject.internal.FailableCache.get(FailableCache.java:48)
08:34:05    at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50)
08:34:05    at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:136)
08:34:05    at com.google.inject.internal.InjectorImpl.initializeBinding(InjectorImpl.java:533)
08:34:05    at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run(AbstractBindingProcessor.java:160)
08:34:05    at com.google.inject.internal.ProcessedBindingData.initializeBindings(ProcessedBindingData.java:44)
08:34:05    at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:123)
08:34:05    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
08:34:05    at com.google.inject.Guice.createInjector(Guice.java:96)
08:34:05    at com.google.inject.Guice.createInjector(Guice.java:73)
08:34:05    at com.google.inject.Guice.createInjector(Guice.java:62)
08:34:05    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:481)
08:34:05    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:206)
08:34:05    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:168)
08:34:05    at hudson.maven.MavenEmbedderUtils.buildPlexusContainer(MavenEmbedderUtils.java:166)
08:34:05    at hudson.maven.MavenEmbedderUtils.buildPlexusContainer(MavenEmbedderUtils.java:159)
08:34:05    at hudson.maven.MavenEmbedder.<init>(MavenEmbedder.java:110)
08:34:05    at hudson.maven.MavenEmbedder.<init>(MavenEmbedder.java:137)
08:34:05    at hudson.maven.MavenUtil.createEmbedder(MavenUtil.java:211)
08:34:05    at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1324)
08:34:05    at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1124)
08:34:05    at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3338)
08:34:05    at hudson.remoting.UserRequest.perform(UserRequest.java:211)
08:34:05    at hudson.remoting.UserRequest.perform(UserRequest.java:54)
08:34:05    at hudson.remoting.Request$2.run(Request.java:376)
08:34:05    at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)
08:34:05    at java.util.concurrent.FutureTask.run(Unknown Source)
08:34:05    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
08:34:05    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
08:34:05    at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:122)
08:34:05    at java.lang.Thread.run(Unknown Source)
08:34:05    Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from VSPWJENKINS16QA.FLEET.AD/10.1.176.32:55500
08:34:05        at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1797)
08:34:05        at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
08:34:05        at hudson.remoting.Channel.call(Channel.java:1001)
08:34:05        at hudson.FilePath.act(FilePath.java:1166)
08:34:05        at hudson.FilePath.act(FilePath.java:1155)
08:34:05        at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.parsePoms(MavenModuleSetBuild.java:985)
08:34:05        at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:689)
08:34:05        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:514)
08:34:05        at hudson.model.Run.execute(Run.java:1888)
08:34:05        at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
08:34:05        at hudson.model.ResourceController.execute(ResourceController.java:99)
08:34:05        at hudson.model.Executor.run(Executor.java:431)
08:34:05 Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.inject.internal.cglib.core.$ReflectUtils
08:34:05    at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init>(FastClassEmitter.java:67)
08:34:05    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:72)
08:34:05    at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
08:34:05    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:216)
08:34:05    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:64)
08:34:05    at com.google.inject.internal.BytecodeGen.newFastClass(BytecodeGen.java:204)
08:34:05    at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:54)
08:34:05    at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:159)
08:34:05    at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90)
08:34:05    at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
08:34:05    at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
08:34:05    at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
08:34:05    at com.google.inject.internal.FailableCache$1.load(FailableCache.java:37)
08:34:05    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3568)
08:34:05    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2350)
08:34:05    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2313)
08:34:05    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2228)

【问题讨论】:

  • 您使用的是哪个版本的 Guice?

标签: java jenkins


【解决方案1】:

首先,我认为您应该切换到 Java 11,因为不再支持 Java 9。其次,NoClassDefFoundError 是当 Java 运行时尝试加载类的定义并且该类定义不再可用时引发的错误。所需的类定义在编译时存在,但在运行时丢失。

我认为您必须检查目标应用程序的类路径并确保存在带有com.google.inject.internal.cglib.core.$ReflectUtils 的 JAR。

UPD 正如卢克在下面指出的那样,异常消息说“无法初始化类......”,所以如果你在 Java 9 上,我认为 com.google.inject.internal.cglib.core.$ReflectUtils 使用属于 jdk.unsupported 的东西,例如sun.misc.Unsafe。在这种情况下,您应该在命令行中添加 --add-modules。或者尝试更新版本的guice。

【讨论】:

  • “NoClassDefFoundError 是当 Java 运行时尝试加载类的定义并且该类定义不再可用时引发的错误”:并非总是如此。如果异常消息显示“无法初始化类...”,就像它在这个问题中所做的那样,那么该类确实存在并且可以找到,但是 JVM 已经尝试并未能对类执行静态初始化,因此给出再做一次。
  • @LukeWoodward 我认为你是对的,我会纠正我的答案
猜你喜欢
  • 2012-10-10
  • 2013-08-08
  • 2020-09-27
  • 2012-08-26
  • 2015-10-29
  • 2017-09-12
  • 2016-07-07
  • 2018-08-01
相关资源
最近更新 更多