Maven: java.lang.NoClassDefFoundError: com/google/inject/internal/cglib/core/$CodeGenerationException

2022-09-03 02:30:00

每当我尝试构建任何maven项目或生成一些原型时,我都会收到以下错误:

[ERROR] Error executing Maven.
[ERROR] java.lang.NoClassDefFoundError: com/google/inject/internal/cglib/core/$CodeGenerationException
[ERROR] Caused by: com/google/inject/internal/cglib/core/$CodeGenerationException
[ERROR] Caused by: com.google.inject.internal.cglib.core.$CodeGenerationException

Maven昨天工作正常,不记得最近更改了其配置中的任何内容。我在 Ubuntu 14.04 上使用 jdk8 oracle 和 jdk7 openjdk(我不时使用 Ubuntu 的 update-alternative --config javac 在 2 个 java 之间切换)。

如果我跑步

mvn -B archetype:generate   -DarchetypeGroupId=org.apache.maven.archetypes   -DgroupId=com.mycompany.app   -DartifactId=my-app -X

我得到这个输出:

username@pcname:~/Desktop/projects/mvn_simple$ mvn -B archetype:generate   -DarchetypeGroupId=org.apache.maven.archetypes   -DgroupId=com.mycompany.app   -DartifactId=my-app -X
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-40-generic", arch: "amd64", family: "unix"
[ERROR] Error executing Maven.
com.google.common.collect.ComputationException: java.lang.NoClassDefFoundError: com/google/inject/internal/cglib/core/$CodeGenerationException
    at com.google.common.collect.MapMaker$ComputingMapAdapter.get(MapMaker.java:890)
    at com.google.inject.internal.FailableCache.get(FailableCache.java:49)
    at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50)
    at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:127)
    at com.google.inject.internal.InjectorImpl.initializeBinding(InjectorImpl.java:530)
    at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run(AbstractBindingProcessor.java:179)
    at com.google.inject.internal.ProcessedBindingData.initializeBindings(ProcessedBindingData.java:44)
    at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:123)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
    at com.google.inject.Guice.createInjector(Guice.java:96)
    at com.google.inject.Guice.createInjector(Guice.java:73)
    at com.google.inject.Guice.createInjector(Guice.java:62)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:470)
    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:196)
    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:160)
    at org.apache.maven.cli.MavenCli.container(MavenCli.java:375)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:191)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.NoClassDefFoundError: com/google/inject/internal/cglib/core/$CodeGenerationException
    at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:156)
    at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90)
    at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
    at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
    at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
    at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:38)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:356)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:182)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:151)
    at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:67)
    at com.google.common.collect.MapMaker$ComputingMapAdapter.get(MapMaker.java:886)
    ... 25 more
Caused by: java.lang.ClassNotFoundException: com.google.inject.internal.cglib.core.$CodeGenerationException
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
    ... 36 more

答案 1

截至2021/10/25,Ubuntu中的maven 3.6.x软件包在Java 17中无法正常工作。

创建文件并提供低于 17 的任何版本。vi ~/.mavenrc

export JAVA_HOME=/usr/lib/jvm/java-16-openjdk-amd64/

如果您希望升级到 java 17 的 3.8.x。https://github.com/m-thirumal/installation_guide/blob/master/maven/upgrade_maven.md

(或者如前所述,使用 sdkman.io 安装与Java相关的工具)


答案 2

对我来说,问题是由于在我的pom中提到了Java 13.xml在服务器计算机上安装了java 17。

所以更新的服务器java版本是它在pom中的样子.xml如果你在Linux上有多个版本的JDK,请使用此命令选择正确的一个

sudo update-alternatives --config java

选择正确的JDK版本,如果您的版本未列出,请使用上面的命令安装它并将其用作活动JDK,之后进行干净的构建并运行

 mvn clean install
 mvn spring-boot:run