0

我正在做一个 jruby 项目,我收到一些与 Nokogiri 相关的 XML PARSING 错误,其控制台日志如下所示:

> XmlDomParserContext.java:94:in `<init>':
> java.lang.NoClassDefFoundError: Could not initialize class
> nokogiri.internals.NokogiriHelpers
>         from XmlDocument.java:317:in `newFromData'
>         from XmlDocument.java:334:in `read_memory'
>         from XmlDocument$INVOKER$s$0$0$read_memory.gen:-1:in `call'
>         from CachingCallSite.java:70:in `call'
>         from FCallManyArgsNode.java:60:in `interpret'
>         from NewlineNode.java:105:in `interpret'
>         from BlockNode.java:71:in `interpret'
>         from IfNode.java:118:in `interpret'
>         from LocalAsgnNode.java:123:in `interpret'
>         from NewlineNode.java:105:in `interpret'
>         from BlockNode.java:71:in `interpret'
>         from ASTInterpreter.java:75:in `INTERPRET_METHOD'
>         from InterpretedMethod.java:112:in `call'
>         from DefaultMethod.java:158:in `call'
>         from CachingCallSite.java:79:in `callBlock'
>         from CachingCallSite.java:85:in `call'
>         from CallManyArgsBlockPassNode.java:57:in `interpret'
>         from NewlineNode.java:105:in `interpret'
>         from ASTInterpreter.java:75:in `INTERPRET_METHOD'
>         from InterpretedMethod.java:182:in `call'
>         from DefaultMethod.java:192:in `call'
>         from CachingCallSite.java:326:in `cacheAndCall'
>         from CachingCallSite.java:170:in `call'
>         from CallOneArgNode.java:57:in `interpret'
>         from DAsgnNode.java:110:in `interpret'
>         from NewlineNode.java:105:in `interpret'
>         from BlockNode.java:71:in `interpret'
>         from RescueNode.java:226:in `executeBody'
>         from RescueNode.java:123:in `interpretWithJavaExceptions'
>         from RescueNode.java:113:in `interpret'
>         from BeginNode.java:83:in `interpret'
>         from NewlineNode.java:105:in `interpret'
>         from BlockNode.java:71:in `interpret'
>         from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
>         from Interpreted19Block.java:209:in `evalBlockBody'
>         from Interpreted19Block.java:197:in `yield'
>         from Interpreted19Block.java:128:in `call'
>         from Block.java:89:in `call'
>         from RubyProc.java:261:in `call'
>         from RubyProc.java:213:in `call'
>         from Ruby.java:2873:in `tearDown'
>         from Ruby.java:2857:in `tearDown'
>         from Main.java:267:in `internalRun'
>         from Main.java:230:in `run'
>         from Main.java:214:in `run'
>         from Main.java:194:in `main'

jruby 版本是 [jruby 1.7.0.RC1 (1.9.3p203) 2012-09-25 8e849de on Java HotSpot(TM) Client VM 1.6.0_37-b06 [Windows XP-x86]]

操作系统:Windows XP

Java 版本:java 版本“1.6.0_37” Java(TM) SE Runtime Environment (build 1.6.0_37-b06) Java HotSpot(TM) Client VM(build 20.12-b01,混合模式,共享)

有人对这个问题有任何想法吗?

4

1 回答 1

0

很可能该类nokogiri.internals.NokogiriHelpers有一个引发异常的静态初始化块,但该异常被某种方式抑制了。

尝试将static块放入try-catch并记录任何异常以找出答案。

class NokogiriHelpers {
    static {
         try { 
             // your initialization stuff
         } catch (Exception e) {
             // log e
         }
    } 
}

请注意,您可能已在其中定义的任何静态常量NokogiriHelpers也有一个静态初始化程序,因此您可能也希望将它们放入 try catch。如果你有

class NokogiriHelpers {
    static int FOO = computeFoo();
}

computeFoo()可能引发未经检查的异常,您必须将其更改为

class NokogiriHelpers {
    static int FOO;
    static {
         try { 
             FOO = computeFoo();
         } catch (Exception e) {
             // log e
         }
    } 
}
于 2012-11-03T07:41:47.210 回答