转换期间的一般错误:找不到合适的 ClassLoader 进行抓取 [英] General error during conversion: No suitable ClassLoader found for grab

查看:52
本文介绍了转换期间的一般错误:找不到合适的 ClassLoader 进行抓取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过下面的代码...

I've try code below...

@Grapes([
    @Grab('org.hsqldb:hsqldb:2.0.0'),
    @GrabConfig(systemClassLoader=true, initContextClassLoader=true)
])
import groovy.sql.Sql
println Class.forName('org.hsqldb.jdbc.JDBCDriver').newInstance()

它在 groovyConsole 中工作,但在 Web Start 中运行失败.以下是错误消息.

It works in groovyConsole, but failed to run with Web Start. Following are error messages.

startup failed:
General error during conversion: No suitable ClassLoader found for grab

java.lang.RuntimeException: No suitable ClassLoader found for grab
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
    at groovy.grape.GrapeIvy.chooseClassLoader(GrapeIvy.groovy:173)
    at groovy.grape.GrapeIvy$chooseClassLoader.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:239)
    at groovy.grape.Grape.grab(Grape.java:141)
    at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:282)
    at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:302)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:839)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:544)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:520)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:497)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:731)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:743)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:698)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:648)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:636)
    at com.lyhdev.mrcode.ScriptLoader.loadGroovy(Unknown Source)
    at com.lyhdev.mrcode.ScriptLoader$loadGroovy.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at Script1.run(Script1.groovy:30)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:650)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:636)
    at com.lyhdev.mrcode.ScriptLoader.loadGroovy(Unknown Source)
    at com.lyhdev.mrcode.ScriptLoader.main(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.javaws.Launcher.executeApplication(Launcher.java:1804)
    at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1750)
    at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1512)
    at com.sun.javaws.Launcher.run(Launcher.java:130)
    at java.lang.Thread.run(Thread.java:662)

1 error 

推荐答案

这完全是关于类加载器所涉及的内容.例如,我在从 ant 运行 groovy 时看到了同样的问题.我似乎是因为在 ant 或 web start 下运行 groovy 时的系统类加载器不是 groovy 类加载器或根加载器.请参阅 GrapeIvy.groovy.

It's all about what classloaders are involved. For example I see the same problem with running groovy from ant. I seems because the system classloader when you run groovy under ant or web start is not a groovy class loader or a root loader. See isValidTargetClassLoader() from GrapeIvy.groovy.

该问题的一个解决方案是确保您有一个 groovy RootLoader,在您的脚本中向其添加所有必要的类路径,然后从您的 groovy 脚本/类运行您的应用程序.我猜网络启动会很棘手.

One solution to the problem would be to make sure you have a groovy RootLoader, add all necessary classpath to it in your script and then run your app from your groovy script/class. Would be tricky with web start I guess.

这篇关于转换期间的一般错误:找不到合适的 ClassLoader 进行抓取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆