1

I know there are like 10 other posts about this topic, but none of the answers work for me right now, not even my own previous post when I ran into this before because that time it was working on my CentOS linux server just fine but was failing when I was running it from IntelliJ on my Mac.

Now I have the opposite problem. It's working on my Mac but not on my linux server. I've just migrated to a new CentOS 7 server and now it's not working when I run it from the command line on my CentOS 7 server.

Here is the stop of my script:

#!/usr/bin/env groovy

@Grab('mysql:mysql-connector-java:5.1.25')
@GrabConfig(systemClassLoader = true)

import groovy.sql.Sql
import groovy.util.GroovyScriptEngine

String reportdate
if (args.length > 0) {
        reportdate = args[0]

} else {
        def today = new Date()
        def yesterday = today - 1
        reportdate = yesterday.format("yyyy-MM-dd")
}

Here is the error output:

$ ./smart_daily_fetch.groovy 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: No suitable ClassLoader found for grab

java.lang.RuntimeException: No suitable ClassLoader found for grab
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
    at groovy.grape.GrapeIvy.chooseClassLoader(GrapeIvy.groovy:175)
    at groovy.grape.GrapeIvy$chooseClassLoader.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:241)
    at groovy.grape.Grape.grab(Grape.java:141)
    at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:283)
    at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:308)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:846)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:550)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:526)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:503)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:302)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:281)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:197)
    at groovy.lang.GroovyShell$2.run(GroovyShell.java:215)
    at groovy.lang.GroovyShell$2.run(GroovyShell.java:213)
    at java.security.AccessController.doPrivileged(Native Method)
    at groovy.lang.GroovyShell.run(GroovyShell.java:213)
    at groovy.lang.GroovyShell.run(GroovyShell.java:159)
    at groovy.ui.GroovyMain.processOnce(GroovyMain.java:550)
    at groovy.ui.GroovyMain.run(GroovyMain.java:337)
    at groovy.ui.GroovyMain.process(GroovyMain.java:323)
    at groovy.ui.GroovyMain.processArgs(GroovyMain.java:120)
    at groovy.ui.GroovyMain.main(GroovyMain.java:100)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
    at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)

1 error
Community
  • 1
  • 1
Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229
  • How did you install groovy? I suggest using sdkman. http://sdkman.io/ – Luis Muñiz Jan 31 '17 at 13:49
  • I used yum to install it. I took your advice, had yum remove groovy, installed sdkman, installed groovy with sdkman, and then groovy worked perfectly. Thank you! If you post this as an answer, I'll accept it. – Kenny Wyland Jan 31 '17 at 19:03

1 Answers1

1

The version that comes with the linux distributions and available on the repositories is usually way out of date. I recommend sdkman to manage the versions of groovy/gradle/grails and many other sdks.

Get it here:

http://sdkman.io/

Luis Muñiz
  • 4,649
  • 1
  • 27
  • 43