Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke groovy with 'java' from command line

I have to ship some groovy code to some users that have only java installed (no grooy, no $groovy_home, etc). I'm trying to invoke groovy from the commandline but I'm having no luck. Here's my bat file:

java -classpath .;lib;bin;bin-groovy introspector.AclCollector

And here's my exception:

Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
       at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 12 more
Could not find the main class: introspector.AclCollector.  Program will exit.

Does anyone have a clue? I have 'groovy-all-1.6-beta-1.jar' in \lib dir.

like image 220
Miguel Ping Avatar asked Dec 18 '08 19:12

Miguel Ping


2 Answers

You have here another example of Groovy app called from Java (in this case, from ant, but the general idea is the same).

java -cp [...];%GROOVY_HOME%/embeddable/groovy-all-1.5.4.jar;[..]

As mentioned by frankowyer, you have the exact groovy jar explicitly listed on the classpath arguments of the java.

Since your clients do not have special environment variable, just replace the %GROOVY_HOME%/... with the complete path to:

  • groovy.jar or
  • goovy-all-VERSION.jar (to minimize any conflict with other libraries)
like image 116
VonC Avatar answered Oct 19 '22 00:10

VonC


I think you need to explicitly list the groovy jar in the classpath

like image 25
frankodwyer Avatar answered Oct 19 '22 02:10

frankodwyer