Intellij Idea 构建错误:NoClassDefFoundError:javax/xml/bind/JAVAXBException

问题描述 投票:0回答:1

我们公司强迫我更换到较新的 Intellij Idea 版本 2023.1,但每当我尝试在 Idea 中构建我们的项目时,我都会遇到错误:

java: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException javax.xml.bind.JAXBException

我用:
java 8u201
阿帕奇maven 3.8.5
Path中的环境变量%JAVA_HOME%、%MAVEN_HOME%及其/bin版本已设置

Intellij Idea重要设置:
项目设置 -> 项目:SDK: 8u201(在 PlatformSettings->SDK 中定义为其 %JAVA_HOME% 路径)
设置 -> 构建、执行、部署 -> 构建工具 -> Maven: Maven 主路径:%MAVEN_HOME%
设置 -> 构建、执行、部署 -> 构建工具 -> Maven -> 导入: 导入器的 VM 选项:-Xmx768m,JDK:项目 JDK

为什么我需要它工作:
我需要在 Intellij 中运行 JUnit 测试,它会自动启动 Intellij 构建,但最终会出现错误。这就是为什么我需要构建才能工作。
我预计问题来自某些 Intellij 设置或 Intellij 周围的某个地方。另请考虑它在之前的 Idea 2022.1.4 中工作的事实,而无需更改项目 pom 或其他项目相关的内容。

我尝试过的:
我尝试使用

mvn clean install
在终端中构建项目,并且有效。
我尝试了 Intellij 右侧 Maven 选项卡中的所有三个魔术按钮。
我尝试使用此堆栈溢出线程中的 VM 选项
-XX:+IgnoreUnrecognizedVMOptions

如何解决java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
我尝试从
%LOCALAPPDATA%\JetBrains

删除所有缓存 我尝试使缓存无效并重新启动 Intellij (选中所有相关复选框)
我尝试将 JDK 从 oracle 切换到 amazon 版本
我尝试将 maven 3.8.5 切换到 3.9.6
我尝试从C盘中删除maven文件夹(有一个文件夹源被导入)

Intellij Idea 构建日志:(使用便携式 JDK 8u211,但它看起来与使用 Correto 8 或 JDK 8u401 的日志相同)

2024-05-02 16:36:12,327 [  29086]   INFO - #o.j.j.i.j.JavaBuilder - java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:168)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
    at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:239)
    at org.jetbrains.jps.incremental.java.JavaBuilder.lambda$compileJava$2(JavaBuilder.java:524)
    at org.jetbrains.jps.incremental.java.JavaBuilder.invokeJavac(JavaBuilder.java:587)
    at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:522)
    at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:366)
    at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:291)
    at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:245)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1553)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1183)
    at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1333)
    at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1148)
    at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:916)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:473)
    at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:196)
    at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:150)
    at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:389)
    at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:214)
    at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:211)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at org.hibernate.jpamodelgen.xml.JpaDescriptorParser.<init>(JpaDescriptorParser.java:77)
    at org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor.init(JPAMetaModelEntityProcessor.java:116)
    at org.jetbrains.jps.javac.APIWrappers$ProcessorWrapper.init(APIWrappers.java:190)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.jetbrains.jps.javac.APIWrappers$1.invoke(APIWrappers.java:362)
    at jdk.proxy2/jdk.proxy2.$Proxy26.init(Unknown Source)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:701)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:828)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:924)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1267)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1382)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1234)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:916)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
    ... 23 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 41 more
2024-05-02 16:36:12,335 [  29094]   INFO - #o.j.j.i.Builder - Dependency analysis found 0 affected files
2024-05-02 16:36:12,341 [  29100]   INFO - #o.j.j.i.j.JavaBuilder - javac 17.0.6 was used to compile [core-connector, aop-utils]
2024-05-02 16:36:12,411 [  29170]   INFO - #o.j.j.c.BuildSession - FilePageCache stats: pageHits=0, pageFastCacheHits=268022, regularPageLoads=355, pageLoadsAboveSizeThreshold=0, pageLoadUs=339434, pageDisposalUs=705, capacityInBytes=524288000, disposedBuffers=355 maxRegisteredFiles=61 maxCacheSizeInBytes=38567936totalSizeCachedBytes=0
2024-05-02 16:36:13,195 [      6]   INFO - #o.j.j.c.BuildMain - ==================================================
2024-05-02 16:36:13,230 [     41]   INFO - #o.j.j.c.BuildMain - Build process started. Classpath: C:/Program Files/JetBrains/IntelliJ IDEA 2023.1/plugins/java/lib/jps-launcher.jar
2024-05-02 16:36:13,483 [    294]   INFO - #o.j.j.c.BuildMain - Connection to IDE established in 236 ms
java maven intellij-idea
1个回答
0
投票

该项目似乎 Intellij 没有使用 Maven 或 Java 8,至少您共享的日志不是 Maven 日志,它说它正在使用 Java 17:

2024-05-02 16:36:12,341 [  29100]   INFO - #o.j.j.i.j.JavaBuilder - javac 17.0.6 was used to compile [core-connector, aop-utils]

您遇到的错误似乎是在 JDK 9+ 中使用 Java 8 JAXB 的典型错误:如何解决 java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

为项目配置 Java 8 应该可以解决该问题。

© www.soinside.com 2019 - 2024. All rights reserved.