Re: Running a Groovy script with a compiled Java class
Paul King <[email protected]>
| Newsgroups | gmane.comp.lang.groovy.user |
|---|---|
| Message-ID | <CAMbkE7SfO8Y7YkD+WeAbrUx0a1cmoNNWUyy8xs4aOkA5iZzVzw@mail.gmail.com> |
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 <[email protected]> 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
>