每次我尝试运行 Groovy 脚本时,我都会收到上面提到的错误消息。我真的不知道如何处理这个错误,我只能给你完整的错误消息。
Information:Groovyc: While compiling tut:java.lang.NoClassDefFoundError: Unable to load class org.apache.groovy.jaxb.extensions.JaxbExtensions due to missing dependency javax/xml/bind/JAXBContext at org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:409) at org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:280) at org.codehaus.groovy.ast.ClassNode.getMethods(ClassNode.java:400) at org.codehaus.groovy.macro.transform.MacroMethodsCache.scanExtClasses(MacroMethodsCache.java:88) at org.codehaus.groovy.macro.transform.MacroMethodsCache.access$000(MacroMethodsCache.java:45) at org.codehaus.groovy.macro.transform.MacroMethodsCache$2.onModule(MacroMethodsCache.java:69) at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromProperties(ExtensionModuleScanner.java:87) at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromMetaInf(ExtensionModuleScanner.java:81) at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModulesFrom(ExtensionModuleScanner.java:63) at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModules(ExtensionModuleScanner.java:54) at org.codehaus.groovy.macro.transform.MacroMethodsCache.getMacroMethodsFromClassLoader(MacroMethodsCache.java:76) at org.codehaus.groovy.macro.transform.MacroMethodsCache$1.provide(MacroMethodsCache.java:53) at org.codehaus.groovy.macro.transform.MacroMethodsCache$1.provide(MacroMethodsCache.java:50) at org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache.getAndPut(ConcurrentCommonCache.java:147) at org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache.getAndPut(ConcurrentCommonCache.java:123) at org.codehaus.groovy.macro.transform.MacroMethodsCache.get(MacroMethodsCache.java:50) at org.codehaus.groovy.macro.transform.MacroCallTransformingVisitor.findMacroMethods(MacroCallTransformingVisitor.java:117) at org.codehaus.groovy.macro.transform.MacroCallTransformingVisitor.visitMethodCallExpression(MacroCallTransformingVisitor.java:88) at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:68) at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:120) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:197) at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40) at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:106) at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69) at org.codehaus.groovy.ast.MethodCallTransformation.visit(MethodCallTransformation.java:49) at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:318) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:965) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:647) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:623) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:600) at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:62) at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:107) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:90) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.runGroovycInThisProcess(InProcessGroovyc.java:175) at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.lambda$runGroovyc$0(InProcessGroovyc.java:94) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:835)
我对每个答案都很满意!
答案1
如果你正在使用 Intellij 或其变体,那么缺少依赖项的问题javax/xml/bind/JAXBContext
可能会在文章中得到解决
Groovy 与 Intellij。
要添加 JAXB Jar:
- 打开项目结构对话
- 点击模块
- 选择依赖项选项卡并添加依赖项,如下所示: