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
Thank you very much.  That answered my question. I am using ant's manifestclasspath operator to build the manifest's class path.

    <!-- Libraries -->
    <property name="lib.commons.cli" value="commons-cli-1.2.jar"/>
    <property name="lib.jacob"       value="jacob-1.14.3.jar"/>
    <property name="lib.jtds"        value="jtds-1.2.jar"/>
    <property name="lib.log4j"       value="log4j.jar"/>
    <property name="lib.scriptom"    value="scriptom-1.6.0.jar"/>
    <property name="lib.groovy"      value="groovy-all-1.7.1.jar"/>

    <path id="path.libraries">
        <fileset id="libraries" dir="${dir.lib}/ext">
            <include name="${lib.commons.cli}" />
            <include name="${lib.groovy}"      />
            <include name="${lib.jacob}"       />
            <include name="${lib.jtds}"        />
            <include name="${lib.log4j}"       />
            <include name="${lib.scriptom}"    />
        </fileset>
    </path>

    <manifestclasspath property="jar.classpath" jarfile="${dir.lib}/${ant.project.name}.jar">
        <classpath>
            <pathelement path="." />
            <fileset refid="libraries"/>
        </classpath>
    </manifestclasspath>
    <echo>jar.classpath: ${jar.classpath}</echo>

    <target name="package" depends="compile">
        <jar jarfile="${dir.lib}/${ant.project.name}.jar">
            <manifest>
                <attribute name="Class-Path" value="${jar.classpath}" />
                <attribute name="Main-Class" value="Test" />
                <attribute name="Built-By" value="${user.name}"/>
                <attribute name="Build-Time" value="${BuildTime}"/>
            </manifest>
            <fileset dir="${dir.bin}"/>
            <fileset dir="${dir.config}"/>
        </jar>
    </target>


 
"He that lives upon hope will die fasting.... He that falls in love with himself will have no rivals."
~~ Benjamin Franklin



From: Roshan Dawrani <roshandawrani@gmail.com>
To: user@groovy.codehaus.org
Sent: Thu, March 18, 2010 2:38:52 PM
Subject: Re: [groovy-user] Very simple script failing when run from jar -- problem with DGM loading

I think when you run a main-class from the jar, "-cp" classpath is ignored - so putting the groovy jar there is no use.

Putting the issue related to putting groovy jar on the bootclasspath aside for a bit, you can run the compiled script class from the jar simply as "java -jar Test.jar" with a manifest like below:

--------------------------------------------------------
Manifest-Version: 1.0
Created-By: 1.5.0_04 (Sun Microsystems Inc.)
Main-Class: Test
Class-Path: lib/groovy-all-1.7.2-SNAPSHOT.jar
--------------------------------------------------------


On Thu, Mar 18, 2010 at 11:55 PM, <polinastya-groovy@yahoo.com> wrote:
I created a bug report for this issue:

GROOVY-4109: NullPointerException: no loader in loadDgmInfo method in GeneratedMetaMethod
 
"He that lives upon hope will die fasting.... He that falls in love with himself will have no rivals."
~~ Benjamin Franklin


Sent: Thu, March 18, 2010 2:10:27 PM

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

I used to be able to jar up my compiled groovy classes and run them from a command line:
 
java
-Xbootclasspath/a:lib\groovy-all-1.5.5.jar -cp somepath -jar myjar.jar

But this capability is now broken in Groovy 1.7.0 due to the attempt to preload DGM methods. This will fail for any compiled groovy class -- any class whatsoever -- at line 152 of GeneratedMetaMethod.java.
  ClassLoader loader = DgmMethodRecord.class.getClassLoader();
  DataInputStream in =
     new DataInputStream(new BufferedInputStream(loader.getResourceAsStream("META-INF/dgminfo")));




From: "polinastya-groovy@yahoo.com" <polinastya-groovy@yahoo.com>
To: user@groovy.codehaus.org
Sent: Thu, March 18, 2010 1:46:04 PM
Subject: Re: [groovy-user] Very simple script failing when run from jar -- problem with DGM loading

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.