Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

Re: [groovy-user] Very simple script failing when run from jar -- problem with DGM loading

polinastya-groovy

2010-03-18

Replies: Find Java Web Hosting

Author LoginPost Reply
Thanks for the suggestion, I am in the right folder. It was easy enough to test an explicit path, but that was not the problem.

This is about as simple a script as you could make
    println "Hello, world"

It runs fine with version 1.5.5, but not with 1.7.0 (or 1.7.1).

I tried this again with 1.7.1 and the error changed.  I think the problem lies with DGM.  There was a change relative to this for 1.7.1 and the error message changed (but it is still throwing a NullPointerException).  The exception is thrown because the ClassLoader is null (see the following code snippet):

  ClassLoader loader = DgmMethodRecord.class.getClassLoader();
  DataInputStream in =
     new DataInputStream(new BufferedInputStream(loader.getResourceAsStream("META-INF/dgminfo")));


Apparently, the class loader is null when the script is loaded from a java command line.  It does not matter whether the JVM is 1.5 or 1.6.  I tried putting groovy-all.jar on both classpath and bootclasspath. This does not matter.  I repeat, it runs fine with version 1.5.5, but not with 1.7.0 (or 1.7.1).

1.7.1 error message:
C:\tal-dealbuilder>dealbuilder.bat

GROOVY_HOME=
PATH=
CLASSPATH=lib\groovy-all-1.7.1.jar;bin;.

c:\progra~1\Java\jre6\bin\java -Xbootclasspath/a:lib\groovy-all-1.7.1.jar -cp lib\groovy-all-1.7.1.jar;bin;. Test

java.lang.NullPointerException
        at org.codehaus.groovy.reflection.GeneratedMetaMethod$DgmMethodRecord.loadDgmInfo(GeneratedMetaMethod.java:152)
        at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:140)
        at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:82)
        at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:60)
        at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:29)
        at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:49)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at Test.class$(Test.groovy)
        at Test.main(Test.groovy)

C:\tal-dealbuilder>dealbuilder.bat

GROOVY_HOME=
PATH=
CLASSPATH=lib\groovy-all-1.7.0.jar;bin;.

java -Xbootclasspath/a:lib\groovy-all-1.7.0.jar;bin;. -jar lib\tal-dealbuilder.jar
Exception in thread "main" java.lang.NullPointerException
        at org.codehaus.groovy.runtime.callsite.CallSiteClassLoader.loadClass(CallSiteClassLoader.java:45)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.loadClass(ClassLoaderForClassArtifacts.java:43)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.define(ClassLoaderForClassArtifacts.java:27)
        at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:71)
        at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:69)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.defineClassAndGetConstructor(ClassLoaderForClassArtifacts.java:69)
        at org.codehaus.groovy.runtime.callsite.CallSiteGenerator.compileStaticMethod(CallSiteGenerator.java:239)
        at org.codehaus.groovy.reflection.CachedMethod.createStaticMetaMethodSite(CachedMethod.java:268)
        at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.createStaticMetaMethodSite(StaticMetaMethodSite.java:111)
        at groovy.lang.MetaClassImpl.createStaticSite(MetaClassImpl.java:2998)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:59)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:144)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129)
        at Test.main(Test.groovy)



From: Tres Finocchiaro <tres.finocchiaro@gmail.com>
To: user@groovy.codehaus.org
Sent: Wed, March 17, 2010 10:05:47 PM
Subject: Re: [groovy-user] Very simple script failing when run from jar

I'm assuming you are in the right folder when you try to run it?

> java -Xbootclasspath/a:lib\groovy-all-1.7.0.jar; -jar lib\tal-dealbuilder.jar

Because lib\ is relative.  C:\folder\lib\ would be explicit.

-Tres



©2008 gg3721.com - Jax Systems, LLC, U.S.A.