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 rac...@merus.eu > On 22 Nov 2021, at 12:09, Blake McBride <blake1...@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 <pa...@asert.com.au > <mailto: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 <blake1...@gmail.com > <mailto:blake1...@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 > >