How to fix "groovy.lang.MissingMethodException" on a method that seems to exist?

4.1k Views Asked by At

I tried to call a static method of class ArtifactoryClientBuilder (coming from artifactory-java-client-services-2.9.2.jar) and got a groovy.lang.MissingMethodException: No signature of method, although the method exists.

The code for that was:

    import org.jfrog.artifactory.client.ArtifactoryClientBuilder
    class Test {
        static void main(String[] args) {
           // Just to check/proof if there is a method 'create'
           def acb = new ArtifactoryClientBuilder().getClass().getMethods()
           acb.each {
              String s = "$it"
              if (s.contains("create")) {
                 println "Found method: $s"
              }
           }
           // Call static method
           def a = ArtifactoryClientBuilder.create()
        }
    }

I put artifactory-java-client-services-2.9.2.jar to ~/.groovy/lib and did a

groovy -d Test.groovy

The result was:

    Found method: public static org.jfrog.artifactory.client.ArtifactoryClientBuilder org.jfrog.artifactory.client.ArtifactoryClientBuilder.create()
    Caught: groovy.lang.MissingMethodException: No signature of method: static org.jfrog.artifactory.client.ArtifactoryClientBuilder.create() is applicable for argument types: () values: []
    Possible solutions: grep(), stream(), print(java.lang.Object), each(groovy.lang.Closure), isCase(java.lang.Object), grep(java.lang.Object)
    groovy.lang.MissingMethodException: No signature of method: static org.jfrog.artifactory.client.ArtifactoryClientBuilder.create() is applicable for argument types: () values: []
    Possible solutions: grep(), stream(), print(java.lang.Object), each(groovy.lang.Closure), isCase(java.lang.Object), grep(java.lang.Object)
        at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1568)
        at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1554)
        at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
        at plugins.cleaner.deleteOutdatedLocalRepoArtifacts.Test.main(Test.groovy:29)
        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.reflection.CachedMethod.invoke(CachedMethod.java:107)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
        at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1513)
        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:1001)
        at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
        at groovy.lang.GroovyShell.run(GroovyShell.java:360)
        at groovy.lang.GroovyShell.run(GroovyShell.java:349)
        at groovy.ui.GroovyMain.processOnce(GroovyMain.java:652)
        at groovy.ui.GroovyMain.run(GroovyMain.java:398)
        at groovy.ui.GroovyMain.access$1400(GroovyMain.java:68)
        at groovy.ui.GroovyMain$GroovyCommand.process(GroovyMain.java:322)
        at groovy.ui.GroovyMain.processArgs(GroovyMain.java:142)
        at groovy.ui.GroovyMain.main(GroovyMain.java:115)
        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:111)
        at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:129)

Although the method pubic static create() was found, calling it results in a MissingMethodException.

What's the reason for that and how to fix that?

Any help is appreciated. Thanks.

1

There are 1 best solutions below

0
user480912 On

Thanks for your valuable inputs, which helped me to figure out what was wrong.

It turned out that "httpclient-4.5.13.jar" was missing. So for the example above I have the following jars in my ~/.groovy/lib:

-rw-r--r--@ 1 dl10skd  staff   71369  3 Aug 09:25 artifactory-java-client-api-2.9.2.jar
-rw-r--r--@ 1 dl10skd  staff  224679  3 Aug 09:25 artifactory-java-client-services-2.9.2.jar
-rw-r--r--  1 dl10skd  staff  780321  4 Aug 11:29 httpclient-4.5.13.jar
-rw-r--r--@ 1 dl10skd  staff  328436  3 Aug 09:25 httpcore-4.4.14.jar

and now it works.