You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Blake McBride <bl...@gmail.com> on 2021/11/22 03:49:07 UTC

Running a Groovy script with a compiled Java class

Greetings,

I can run a simple Groovy class (TestGroovy.groovy) without explicitly
compiling it as follows:

java -jar groovy-3.0.9-indy.jar TestGroovy

I have a compiled Java class file named TestJava.class

I am not using any package declarations.  everything is in the current
directory.

I changed TestGroovy.groovy to call my TestJava.class file, however, this
is what I am getting:

$ java -jar groovy-3.0.9-indy.jar TestGroovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
failed:
/home/blake/groovy/TestGroovy.groovy: 7: Apparent variable 'TestJava' was
found in a static scope but doesn't refer to a local variable, static field
or class. Possible causes:
You attempted to reference a variable in the binding or an instance
variable from a static context.
You misspelled a classname or statically imported field. Please check the
spelling.
You attempted to use a method 'TestJava' but left out brackets in a place
not allowed by the grammar.
 @ line 7, column 3.
    TestJava.javaMethod()
     ^

1 error

I also tried:   java -cp . -jar groovy-3.0.9-indy.jar -cp .  TestGroovy
With the same error.

Basically, I am trying to run a Groovy file and have it call a Java class
that I am supplying.

I am attaching the Java and Groovy files.  Sure appreciate any help.

Blake McBride

Re: Running a Groovy script with a compiled Java class

Posted by Maarten Boekhold <bo...@gmx.com>.
Another way of doing this:

#!/bin/bash
DUMMY=''' '
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

if [ -z "$JAVA_HOME" ]; then
    echo "JAVA_HOME is not set"
    exit
fi


if [ ! -f "$JAVA_HOME/bin/java" ]; then
    echo "JAVA_HOME does not point to a valid java installation"
    exit
fi


# This was written when "groovy-all" still existed. It will
# need to be updated to include all required groovy jars
# into the CLASSPATH...
GROOVY_EMBED=/opt/groovy/lib/groovy-all-2.1.8.jar


"$JAVA_HOME"/bin/java \
    -Xmx128m \
    -Dprogram.name="" \
    "-Dtools.jar=$JAVA_HOME/lib/tools.jar" \
    "-Dscript.name=${0##*/}" \
    -classpath "$GROOVY_EMBED:$JAVA_HOME/lib/tools.jar" \
    org.codehaus.groovy.tools.GroovyStarter \
    --main groovy.ui.GroovyMain \
    "$0" $@
exit $?
' '''


println "Put your groovy script code here"

On November 23, 2021 09:27:50 Maarten Boekhold <bo...@gmx.com> wrote:
> Another neat way to do this is to embed your groovy script inside a bash
> script as per the method described in the following post:
>
> https://mail-archives.apache.org/mod_mbox/groovy-users/201506.mbox/%3C556EE6DF.4020604@gmx.com%3E
>
> Maarten
>
> On November 22, 2021 16:56:55 Blake McBride <bl...@gmail.com> wrote:
>> Greetings,
>>
>> For my case, I think I have found a perfect solution.  I created the
>> following bash script named run:
>>
>> -------------------------------
>>
>> #!/bin/bash
>>
>> # This script allows the running of a Groovy file in the context of the
>> # entire system.
>>
>> JAR_PATH=`dirname $0`/../lib
>> CLASSES_PATH=`dirname $0`/../build/web/WEB-INF/classes
>>
>> THE_CLASSPATH=.
>> for i in `ls $JAR_PATH/*.jar`
>> do
>> THE_CLASSPATH=${THE_CLASSPATH}:${i}
>> done
>>
>> THE_CLASSPATH=${THE_CLASSPATH}:${CLASSES_PATH}
>>
>> java -cp ${THE_CLASSPATH} groovy.ui.GroovyMain "$@"
>>
>>
>> ------------------------------------
>>
>> I am then able to run a groovy file in the context of the rest of my system
>> (this system has 9500 classes and 89 jar files).  I can now simply do:
>>
>> run MyGroovyFile
>>
>> Thanks!
>>
>> Blake
>>
>>
>>
>> On Mon, Nov 22, 2021 at 6:09 AM Blake McBride <bl...@gmail.com> wrote:
>> Hi Paul,
>>
>> That worked great.  Thank you!
>>
>> However, it would be very convenient if I could specify the -cp using the
>> "java -jar" method like so:
>>
>> java -jar groovy-3.0.9-indy.jar -cp . TestGroovy
>>
>> The reason is that the example I gave you is a simplified example of what I
>> am actually doing.  Although the method you gave me does work in my
>> situation too, it is situationally somewhat awkward.  It would be very
>> convenient if the groovy jar accepted and used the -cp command.  Is there
>> any way I can do that?
>>
>> (Just FYI, I am working on https://github.com/blakemcbride/Kiss   In
>> particular, see section 7 of
>> https://htmlpreview.github.io/?https://github.com/blakemcbride/Kiss/blob/master/manual/man/index.html
>>  )
>>
>> Thanks!
>>
>> Blake
>>
>>
>>
>>
>> On Mon, Nov 22, 2021 at 1:19 AM Paul King <pa...@asert.com.au> wrote:
>> Hi Blake,
>>
>> If you add the following line into your TestGroovy script:
>> println System.getProperty('java.class.path')
>> you will see that "." from the -cp commandline switch to java isn't
>> passed through to Groovy when using java -jar.
>>
>> You can instead use (semicolon would be the path separator on Windows):
>> java -cp /path/to/groovy/jar:. groovy.ui.GroovyMain TestGroovy
>>
>> or:
>> /path/to/groovy TestGroovy
>>
>>
>>
>> Cheers, Paul.
>>
>> On Mon, Nov 22, 2021 at 1:49 PM Blake McBride <bl...@gmail.com> wrote:
>>>
>>> Greetings,
>>>
>>> I can run a simple Groovy class (TestGroovy.groovy) without explicitly
>>> compiling it as follows:
>>>
>>> java -jar groovy-3.0.9-indy.jar TestGroovy
>>>
>>> I have a compiled Java class file named TestJava.class
>>>
>>> I am not using any package declarations.  everything is in the current
>>> directory.
>>>
>>> I changed TestGroovy.groovy to call my TestJava.class file, however, this
>>> is what I am getting:
>>>
>>> $ java -jar groovy-3.0.9-indy.jar TestGroovy
>>> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>>> /home/blake/groovy/TestGroovy.groovy: 7: Apparent variable 'TestJava' was
>>> found in a static scope but doesn't refer to a local variable, static field
>>> or class. Possible causes:
>>> You attempted to reference a variable in the binding or an instance
>>> variable from a static context.
>>> You misspelled a classname or statically imported field. Please check the
>>> spelling.
>>> You attempted to use a method 'TestJava' but left out brackets in a place
>>> not allowed by the grammar.
>>>  @ line 7, column 3.
>>>     TestJava.javaMethod()
>>>      ^
>>>
>>> 1 error
>>>
>>> I also tried:   java -cp . -jar groovy-3.0.9-indy.jar -cp .  TestGroovy
>>> With the same error.
>>>
>>> Basically, I am trying to run a Groovy file and have it call a Java class
>>> that I am supplying.
>>>
>>> I am attaching the Java and Groovy files.  Sure appreciate any help.
>>>
>>> Blake McBride
>>>


Re: Running a Groovy script with a compiled Java class

Posted by Maarten Boekhold <bo...@gmx.com>.
Another neat way to do this is to embed your groovy script inside a bash
script as per the method described in the following post:

https://mail-archives.apache.org/mod_mbox/groovy-users/201506.mbox/%3C556EE6DF.4020604@gmx.com%3E

Maarten

On November 22, 2021 16:56:55 Blake McBride <bl...@gmail.com> wrote:
> Greetings,
>
> For my case, I think I have found a perfect solution.  I created the
> following bash script named run:
>
> -------------------------------
>
> #!/bin/bash
>
> # This script allows the running of a Groovy file in the context of the
> # entire system.
>
> JAR_PATH=`dirname $0`/../lib
> CLASSES_PATH=`dirname $0`/../build/web/WEB-INF/classes
>
> THE_CLASSPATH=.
> for i in `ls $JAR_PATH/*.jar`
> do
> THE_CLASSPATH=${THE_CLASSPATH}:${i}
> done
>
> THE_CLASSPATH=${THE_CLASSPATH}:${CLASSES_PATH}
>
> java -cp ${THE_CLASSPATH} groovy.ui.GroovyMain "$@"
>
>
> ------------------------------------
>
> I am then able to run a groovy file in the context of the rest of my system
> (this system has 9500 classes and 89 jar files).  I can now simply do:
>
> run MyGroovyFile
>
> Thanks!
>
> Blake
>
>
>
> On Mon, Nov 22, 2021 at 6:09 AM Blake McBride <bl...@gmail.com> wrote:
> Hi Paul,
>
> That worked great.  Thank you!
>
> However, it would be very convenient if I could specify the -cp using the
> "java -jar" method like so:
>
> java -jar groovy-3.0.9-indy.jar -cp . TestGroovy
>
> The reason is that the example I gave you is a simplified example of what I
> am actually doing.  Although the method you gave me does work in my
> situation too, it is situationally somewhat awkward.  It would be very
> convenient if the groovy jar accepted and used the -cp command.  Is there
> any way I can do that?
>
> (Just FYI, I am working on https://github.com/blakemcbride/Kiss   In
> particular, see section 7 of
> https://htmlpreview.github.io/?https://github.com/blakemcbride/Kiss/blob/master/manual/man/index.html
>  )
>
> Thanks!
>
> Blake
>
>
>
>
> On Mon, Nov 22, 2021 at 1:19 AM Paul King <pa...@asert.com.au> wrote:
> Hi Blake,
>
> If you add the following line into your TestGroovy script:
> println System.getProperty('java.class.path')
> you will see that "." from the -cp commandline switch to java isn't
> passed through to Groovy when using java -jar.
>
> You can instead use (semicolon would be the path separator on Windows):
> java -cp /path/to/groovy/jar:. groovy.ui.GroovyMain TestGroovy
>
> or:
> /path/to/groovy TestGroovy
>
>
>
> Cheers, Paul.
>
> On Mon, Nov 22, 2021 at 1:49 PM Blake McBride <bl...@gmail.com> wrote:
>>
>> Greetings,
>>
>> I can run a simple Groovy class (TestGroovy.groovy) without explicitly
>> compiling it as follows:
>>
>> java -jar groovy-3.0.9-indy.jar TestGroovy
>>
>> I have a compiled Java class file named TestJava.class
>>
>> I am not using any package declarations.  everything is in the current
>> directory.
>>
>> I changed TestGroovy.groovy to call my TestJava.class file, however, this
>> is what I am getting:
>>
>> $ java -jar groovy-3.0.9-indy.jar TestGroovy
>> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>> /home/blake/groovy/TestGroovy.groovy: 7: Apparent variable 'TestJava' was
>> found in a static scope but doesn't refer to a local variable, static field
>> or class. Possible causes:
>> You attempted to reference a variable in the binding or an instance
>> variable from a static context.
>> You misspelled a classname or statically imported field. Please check the
>> spelling.
>> You attempted to use a method 'TestJava' but left out brackets in a place
>> not allowed by the grammar.
>>  @ line 7, column 3.
>>     TestJava.javaMethod()
>>      ^
>>
>> 1 error
>>
>> I also tried:   java -cp . -jar groovy-3.0.9-indy.jar -cp .  TestGroovy
>> With the same error.
>>
>> Basically, I am trying to run a Groovy file and have it call a Java class
>> that I am supplying.
>>
>> I am attaching the Java and Groovy files.  Sure appreciate any help.
>>
>> Blake McBride
>>


Re: Running a Groovy script with a compiled Java class

Posted by Blake McBride <bl...@gmail.com>.
Thanks for the feedback!!

On Mon, Nov 22, 2021 at 11:49 PM Balachandran Sivakumar <
benignbala@gmail.com> wrote:

> Hi Blake,
>
>
> > -------------------------------
> >
> > #!/bin/bash
> >
> > # This script allows the running of a Groovy file in the context of the
> > # entire system.
> >
> > JAR_PATH=`dirname $0`/../lib
> > CLASSES_PATH=`dirname $0`/../build/web/WEB-INF/classes
> >
>
>     Just a quick word of caution not directly related to the approach
> - You might want to add double quotes around $0 to handle paths that
> have spaces in them. Also, it is preferable to use $(dirname "$0")
> instead of backticks. Backticks can cause certain unexpected problems
> when either being nested or when handling values that have quotes.
> Thanks
>
>
> --
> Thank you
> Balachandran Sivakumar
>

Re: Running a Groovy script with a compiled Java class

Posted by Balachandran Sivakumar <be...@gmail.com>.
Hi Blake,


> -------------------------------
>
> #!/bin/bash
>
> # This script allows the running of a Groovy file in the context of the
> # entire system.
>
> JAR_PATH=`dirname $0`/../lib
> CLASSES_PATH=`dirname $0`/../build/web/WEB-INF/classes
>

    Just a quick word of caution not directly related to the approach
- You might want to add double quotes around $0 to handle paths that
have spaces in them. Also, it is preferable to use $(dirname "$0")
instead of backticks. Backticks can cause certain unexpected problems
when either being nested or when handling values that have quotes.
Thanks


-- 
Thank you
Balachandran Sivakumar

Re: Running a Groovy script with a compiled Java class

Posted by Blake McBride <bl...@gmail.com>.
Greetings,

For my case, I think I have found a perfect solution.  I created the
following bash script named run:

-------------------------------

#!/bin/bash

# This script allows the running of a Groovy file in the context of the
# entire system.

JAR_PATH=`dirname $0`/../lib
CLASSES_PATH=`dirname $0`/../build/web/WEB-INF/classes

THE_CLASSPATH=.
for i in `ls $JAR_PATH/*.jar`
do
    THE_CLASSPATH=${THE_CLASSPATH}:${i}
done

THE_CLASSPATH=${THE_CLASSPATH}:${CLASSES_PATH}

java -cp ${THE_CLASSPATH} groovy.ui.GroovyMain "$@"


------------------------------------

I am then able to run a groovy file in the context of the rest of my system
(this system has 9500 classes and 89 jar files).  I can now simply do:

run MyGroovyFile

Thanks!

Blake



On Mon, Nov 22, 2021 at 6:09 AM Blake McBride <bl...@gmail.com> wrote:

> Hi Paul,
>
> That worked great.  Thank you!
>
> However, it would be very convenient if I could specify the -cp using the
> "java -jar" method like so:
>
> java -jar groovy-3.0.9-indy.jar -cp . TestGroovy
>
> The reason is that the example I gave you is a simplified example of what
> I am actually doing.  Although the method you gave me does work in my
> situation too, it is situationally somewhat awkward.  It would be very
> convenient if the groovy jar accepted and used the -cp command.  Is there
> any way I can do that?
>
> (Just FYI, I am working on https://github.com/blakemcbride/Kiss   In
> particular, see section 7 of
> https://htmlpreview.github.io/?https://github.com/blakemcbride/Kiss/blob/master/manual/man/index.html
> )
>
> Thanks!
>
> Blake
>
>
>
>
> On Mon, Nov 22, 2021 at 1:19 AM Paul King <pa...@asert.com.au> wrote:
>
>> Hi Blake,
>>
>> If you add the following line into your TestGroovy script:
>> println System.getProperty('java.class.path')
>> you will see that "." from the -cp commandline switch to java isn't
>> passed through to Groovy when using java -jar.
>>
>> You can instead use (semicolon would be the path separator on Windows):
>> java -cp /path/to/groovy/jar:. groovy.ui.GroovyMain TestGroovy
>>
>> or:
>> /path/to/groovy TestGroovy
>>
>>
>>
>> Cheers, Paul.
>>
>> On Mon, Nov 22, 2021 at 1:49 PM Blake McBride <bl...@gmail.com>
>> wrote:
>> >
>> > Greetings,
>> >
>> > I can run a simple Groovy class (TestGroovy.groovy) without explicitly
>> compiling it as follows:
>> >
>> > java -jar groovy-3.0.9-indy.jar TestGroovy
>> >
>> > I have a compiled Java class file named TestJava.class
>> >
>> > I am not using any package declarations.  everything is in the current
>> directory.
>> >
>> > I changed TestGroovy.groovy to call my TestJava.class file, however,
>> this is what I am getting:
>> >
>> > $ java -jar groovy-3.0.9-indy.jar TestGroovy
>> > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
>> failed:
>> > /home/blake/groovy/TestGroovy.groovy: 7: Apparent variable 'TestJava'
>> was found in a static scope but doesn't refer to a local variable, static
>> field or class. Possible causes:
>> > You attempted to reference a variable in the binding or an instance
>> variable from a static context.
>> > You misspelled a classname or statically imported field. Please check
>> the spelling.
>> > You attempted to use a method 'TestJava' but left out brackets in a
>> place not allowed by the grammar.
>> >  @ line 7, column 3.
>> >     TestJava.javaMethod()
>> >      ^
>> >
>> > 1 error
>> >
>> > I also tried:   java -cp . -jar groovy-3.0.9-indy.jar -cp .  TestGroovy
>> > With the same error.
>> >
>> > Basically, I am trying to run a Groovy file and have it call a Java
>> class that I am supplying.
>> >
>> > I am attaching the Java and Groovy files.  Sure appreciate any help.
>> >
>> > Blake McBride
>> >
>>
>

Re: Running a Groovy script with a compiled Java class

Posted by Rachel Greenham <ra...@merus.eu>.
It’s a java thing, not a groovy thing. That’s just what java -jar does.

You may be better off having groovy *installed* as opposed to invoking via a java command pointing at the jar. Then you can just use eg:

groovy -cp . TestGroovy.groovy

And as it’s being run as a script you don’t even need the class boilerplate in the groovy source.

-- 
Rachel Greenham
rachel@merus.eu



> On 22 Nov 2021, at 12:09, Blake McBride <bl...@gmail.com> wrote:
> 
> Hi Paul,
> 
> That worked great.  Thank you!
> 
> However, it would be very convenient if I could specify the -cp using the "java -jar" method like so:
> 
> java -jar groovy-3.0.9-indy.jar -cp . TestGroovy
> 
> The reason is that the example I gave you is a simplified example of what I am actually doing.  Although the method you gave me does work in my situation too, it is situationally somewhat awkward.  It would be very convenient if the groovy jar accepted and used the -cp command.  Is there any way I can do that?
> 
> (Just FYI, I am working on https://github.com/blakemcbride/Kiss <https://github.com/blakemcbride/Kiss>   In particular, see section 7 of https://htmlpreview.github.io/?https://github.com/blakemcbride/Kiss/blob/master/manual/man/index.html <https://htmlpreview.github.io/?https://github.com/blakemcbride/Kiss/blob/master/manual/man/index.html>  )
> 
> Thanks!
> 
> Blake
> 
> 
> 
> 
> On Mon, Nov 22, 2021 at 1:19 AM Paul King <paulk@asert.com.au <ma...@asert.com.au>> wrote:
> Hi Blake,
> 
> If you add the following line into your TestGroovy script:
> println System.getProperty('java.class.path')
> you will see that "." from the -cp commandline switch to java isn't
> passed through to Groovy when using java -jar.
> 
> You can instead use (semicolon would be the path separator on Windows):
> java -cp /path/to/groovy/jar:. groovy.ui.GroovyMain TestGroovy
> 
> or:
> /path/to/groovy TestGroovy
> 
> 
> 
> Cheers, Paul.
> 
> On Mon, Nov 22, 2021 at 1:49 PM Blake McBride <blake1024@gmail.com <ma...@gmail.com>> wrote:
> >
> > Greetings,
> >
> > I can run a simple Groovy class (TestGroovy.groovy) without explicitly compiling it as follows:
> >
> > java -jar groovy-3.0.9-indy.jar TestGroovy
> >
> > I have a compiled Java class file named TestJava.class
> >
> > I am not using any package declarations.  everything is in the current directory.
> >
> > I changed TestGroovy.groovy to call my TestJava.class file, however, this is what I am getting:
> >
> > $ java -jar groovy-3.0.9-indy.jar TestGroovy
> > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> > /home/blake/groovy/TestGroovy.groovy: 7: Apparent variable 'TestJava' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
> > You attempted to reference a variable in the binding or an instance variable from a static context.
> > You misspelled a classname or statically imported field. Please check the spelling.
> > You attempted to use a method 'TestJava' but left out brackets in a place not allowed by the grammar.
> >  @ line 7, column 3.
> >     TestJava.javaMethod()
> >      ^
> >
> > 1 error
> >
> > I also tried:   java -cp . -jar groovy-3.0.9-indy.jar -cp .  TestGroovy
> > With the same error.
> >
> > Basically, I am trying to run a Groovy file and have it call a Java class that I am supplying.
> >
> > I am attaching the Java and Groovy files.  Sure appreciate any help.
> >
> > Blake McBride
> >


Re: Running a Groovy script with a compiled Java class

Posted by Blake McBride <bl...@gmail.com>.
Hi Paul,

That worked great.  Thank you!

However, it would be very convenient if I could specify the -cp using the
"java -jar" method like so:

java -jar groovy-3.0.9-indy.jar -cp . TestGroovy

The reason is that the example I gave you is a simplified example of what I
am actually doing.  Although the method you gave me does work in my
situation too, it is situationally somewhat awkward.  It would be very
convenient if the groovy jar accepted and used the -cp command.  Is there
any way I can do that?

(Just FYI, I am working on https://github.com/blakemcbride/Kiss   In
particular, see section 7 of
https://htmlpreview.github.io/?https://github.com/blakemcbride/Kiss/blob/master/manual/man/index.html
)

Thanks!

Blake




On Mon, Nov 22, 2021 at 1:19 AM Paul King <pa...@asert.com.au> wrote:

> Hi Blake,
>
> If you add the following line into your TestGroovy script:
> println System.getProperty('java.class.path')
> you will see that "." from the -cp commandline switch to java isn't
> passed through to Groovy when using java -jar.
>
> You can instead use (semicolon would be the path separator on Windows):
> java -cp /path/to/groovy/jar:. groovy.ui.GroovyMain TestGroovy
>
> or:
> /path/to/groovy TestGroovy
>
>
>
> Cheers, Paul.
>
> On Mon, Nov 22, 2021 at 1:49 PM Blake McBride <bl...@gmail.com> wrote:
> >
> > Greetings,
> >
> > I can run a simple Groovy class (TestGroovy.groovy) without explicitly
> compiling it as follows:
> >
> > java -jar groovy-3.0.9-indy.jar TestGroovy
> >
> > I have a compiled Java class file named TestJava.class
> >
> > I am not using any package declarations.  everything is in the current
> directory.
> >
> > I changed TestGroovy.groovy to call my TestJava.class file, however,
> this is what I am getting:
> >
> > $ java -jar groovy-3.0.9-indy.jar TestGroovy
> > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> > /home/blake/groovy/TestGroovy.groovy: 7: Apparent variable 'TestJava'
> was found in a static scope but doesn't refer to a local variable, static
> field or class. Possible causes:
> > You attempted to reference a variable in the binding or an instance
> variable from a static context.
> > You misspelled a classname or statically imported field. Please check
> the spelling.
> > You attempted to use a method 'TestJava' but left out brackets in a
> place not allowed by the grammar.
> >  @ line 7, column 3.
> >     TestJava.javaMethod()
> >      ^
> >
> > 1 error
> >
> > I also tried:   java -cp . -jar groovy-3.0.9-indy.jar -cp .  TestGroovy
> > With the same error.
> >
> > Basically, I am trying to run a Groovy file and have it call a Java
> class that I am supplying.
> >
> > I am attaching the Java and Groovy files.  Sure appreciate any help.
> >
> > Blake McBride
> >
>

Re: Running a Groovy script with a compiled Java class

Posted by Paul King <pa...@asert.com.au>.
Hi Blake,

If you add the following line into your TestGroovy script:
println System.getProperty('java.class.path')
you will see that "." from the -cp commandline switch to java isn't
passed through to Groovy when using java -jar.

You can instead use (semicolon would be the path separator on Windows):
java -cp /path/to/groovy/jar:. groovy.ui.GroovyMain TestGroovy

or:
/path/to/groovy TestGroovy



Cheers, Paul.

On Mon, Nov 22, 2021 at 1:49 PM Blake McBride <bl...@gmail.com> wrote:
>
> Greetings,
>
> I can run a simple Groovy class (TestGroovy.groovy) without explicitly compiling it as follows:
>
> java -jar groovy-3.0.9-indy.jar TestGroovy
>
> I have a compiled Java class file named TestJava.class
>
> I am not using any package declarations.  everything is in the current directory.
>
> I changed TestGroovy.groovy to call my TestJava.class file, however, this is what I am getting:
>
> $ java -jar groovy-3.0.9-indy.jar TestGroovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> /home/blake/groovy/TestGroovy.groovy: 7: Apparent variable 'TestJava' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
> You attempted to reference a variable in the binding or an instance variable from a static context.
> You misspelled a classname or statically imported field. Please check the spelling.
> You attempted to use a method 'TestJava' but left out brackets in a place not allowed by the grammar.
>  @ line 7, column 3.
>     TestJava.javaMethod()
>      ^
>
> 1 error
>
> I also tried:   java -cp . -jar groovy-3.0.9-indy.jar -cp .  TestGroovy
> With the same error.
>
> Basically, I am trying to run a Groovy file and have it call a Java class that I am supplying.
>
> I am attaching the Java and Groovy files.  Sure appreciate any help.
>
> Blake McBride
>