识别 Groovy jar 中缺失的导入

huangapple go评论91阅读模式
英文:

Identifying missing imports in Groovy jar

问题

我正在尝试为我编写的Groovy程序创建一个jar文件(BINSIC - 一个运行BASIC代码的解释器兼DSL:https://github.com/mcmenaminadrian/BINSIC)。

我面临一个基本问题,即代码在开发机器上运行良好(尽管速度很慢),但在部署时失败(见下文) - 即使在已安装完整Groovy的机器上也是如此。看起来像是我未能将某些内容导入到jar文件中,然后进行调用,尽管我不知道为什么当我安装了完整的Groovy时会失败。我在几个不同版本的Java上(还使用sdkman)激活时也遇到了相同的问题。

我该怎么做才能使代码在部署时正常工作?有人知道吗?

设置默认的Groovy版本为3.0.2。
lorraine@Kobani:~/Downloads$ java -jar binsic.jar test.bas
"main"线程中的异常java.lang.reflect.InvocationTargetException
在java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
在java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.base/java.lang.reflect.Method.invoke(Method.java:566)
在org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
由于缺少依赖javax/xml/bind/JAXBContext,导致无法加载类org.apache.groovy.jaxb.extensions.JaxbExtensions
在org.codehaus.groovy.vmplugin.v8.Java8.configureClassNode(Java8.java:458)
在org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:274)
在org.codehaus.groovy.ast.ClassNode.getMethods(ClassNode.java:396)
在org.codehaus.groovy.transform.stc.AbstractExtensionMethodCache.scan(AbstractExtensionMethodCache.java:116)
在org.codehaus.groovy.transform.stc.AbstractExtensionMethodCache.getMethods(AbstractExtensionMethodCache.java:97)
在org.codehaus.groovy.transform.stc.AbstractExtensionMethodCache.getMethodsFromClassLoader(AbstractExtensionMethodCache.java:73)
在org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
在org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
在org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:115)
在org.codehaus.groovy.transform.stc.AbstractExtensionMethodCache.get(AbstractExtensionMethodCache.java:51)
在org.codehaus.groovy.macro.transform.MacroCallTransformingVisitor.findMacroMethods(MacroCallTransformingVisitor.java:119)
在org.codehaus.groovy.macro.transform.MacroCallTransformingVisitor.visitMethodCallExpression(MacroCallTransformingVisitor.java:90)
在org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:76)
在org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:117)
在org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:200)
在org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
在org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86)
在org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:164)
在org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
在org.codehaus.groovy.ast.MethodCallTransformation.visit(MethodCallTransformation.java:42)
在org.codehaus.groovy.transform.ASTTransformationVisitor.lambda$addPhaseOperationsForGlobalTransforms$4(ASTTransformationVisitor.java:336)
在org.codehaus.groovy.control.CompilationUnit$ISourceUnitOperation.doPhaseOperation(CompilationUnit.java:880)
在org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:650)
在org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:627)
在groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389)
在groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332)
在org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
在org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
在groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330)
在groovy.lang.GroovyShell.parseClass(GroovyShell.java:530)
在groovy.lang.GroovyShell.parse(GroovyShell.java:542)
在groovy.lang.GroovyShell.evaluate(GroovyShell.java:430)
在groovy.lang.GroovyShell.evaluate(GroovyShell.java:474)
在org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:274)
在binsic.BinsicEngine.process(Binsic.groovy:53)
在org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:274)
在binsic.Binsic.run(Binsic.groovy:81)
在java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
在java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.base/java.lang.reflect.Method.invoke(Method.java:566)
在org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
在groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1262)
在groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1029)
在org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:1027)
在org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:1010)
在org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:442)
在org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:274)
在binsic.Binsic.main(Binsic.groovy)
... 5 more

英文:

I am trying to create a jar file for a Groovy program I have written (BINSIC - an interpreter cum DSL that runs BASIC code: https://github.com/mcmenaminadrian/BINSIC).

I have a fundamental problem in that the code runs fine (if very slowly) on the development machine but fails on deployment (see below) - even on a box where I have installed a full Groovy installation. It looks like I'm failing to import something into the jar which is then called, though I don't know why that would fail when I have a full Groovy install. I have had the same problem with several different versions of Java (also using sdkman) activated.

What do I have to do to get the code to work on deployment? Does anyone know?

Setting groovy 3.0.2 as default.
lorraine@Kobani:~/Downloads$ java -jar binsic.jar test.bas
Exception in thread "main" java.lang.reflect.InvocationTargetException
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:566)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: 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.v8.Java8.configureClassNode(Java8.java:458)
at org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:274)
at org.codehaus.groovy.ast.ClassNode.getMethods(ClassNode.java:396)
at org.codehaus.groovy.transform.stc.AbstractExtensionMethodCache.scan(AbstractExtensionMethodCache.java:116)
at org.codehaus.groovy.transform.stc.AbstractExtensionMethodCache.getMethods(AbstractExtensionMethodCache.java:97)
at org.codehaus.groovy.transform.stc.AbstractExtensionMethodCache.getMethodsFromClassLoader(AbstractExtensionMethodCache.java:73)
at org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
at org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
at org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:115)
at org.codehaus.groovy.transform.stc.AbstractExtensionMethodCache.get(AbstractExtensionMethodCache.java:51)
at org.codehaus.groovy.macro.transform.MacroCallTransformingVisitor.findMacroMethods(MacroCallTransformingVisitor.java:119)
at org.codehaus.groovy.macro.transform.MacroCallTransformingVisitor.visitMethodCallExpression(MacroCallTransformingVisitor.java:90)
at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:76)
at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:117)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:200)
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:164)
at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
at org.codehaus.groovy.ast.MethodCallTransformation.visit(MethodCallTransformation.java:42)
at org.codehaus.groovy.transform.ASTTransformationVisitor.lambda$addPhaseOperationsForGlobalTransforms$4(ASTTransformationVisitor.java:336)
at org.codehaus.groovy.control.CompilationUnit$ISourceUnitOperation.doPhaseOperation(CompilationUnit.java:880)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:650)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:627)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389)
at groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332)
at org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
at org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:530)
at groovy.lang.GroovyShell.parse(GroovyShell.java:542)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:430)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:474)
at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:274)
at binsic.BinsicEngine.process(Binsic.groovy:53)
at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:274)
at binsic.Binsic.run(Binsic.groovy:81)
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:566)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1262)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1029)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:1027)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:1010)
at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:442)
at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:274)
at binsic.Binsic.main(Binsic.groovy)
... 5 more

答案1

得分: 1

以下是翻译好的内容:

根错误消息:

> 引发原因:java.lang.NoClassDefFoundError:
无法加载类org.apache.groovy.jaxb.extensions.JaxbExtensions
原因是
缺少依赖javax/xml/bind/JAXBContext

打开网站https://search.maven.org/

并搜索完整类名,前缀为 fc:

类似这样 fc:javax.xml.bind.JAXBContext

https://search.maven.org/search?q=fc:javax.xml.bind.JAXBContext

英文:

the root error message:

> Caused by: java.lang.NoClassDefFoundError:
Unable to load class org.apache.groovy.jaxb.extensions.JaxbExtensions
due to
missing dependency javax/xml/bind/JAXBContext

open site https://search.maven.org/

and search for full class name that s missing with prefix fc:

like this fc:javax.xml.bind.JAXBContext

https://search.maven.org/search?q=fc:javax.xml.bind.JAXBContext

huangapple
  • 本文由 发表于 2020年4月5日 03:11:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/61033421.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定