0

I am trying to access buckets on S3(just printing the names of the buckets for now) using Groovy(2.4) and intellij idea and I am getting an error. My current code is:

import org.jets3t.service.impl.rest.httpclient.RestS3Service
import org.jets3t.service.model.S3Bucket
import org.jets3t.service.model.S3Object
import org.jets3t.service.security.AWSCredentials

@Grab('net.java.dev.jets3t:jets3t:0.9.0')


class s3_read {



    static void main(def args){

        String awsAccessKey = "YOUR_AWS_ACCESS_KEY";
        String awsSecretKey = "YOUR_AWS_SECRET_KEY";
        AWSCredentials awsCredentials =
                new AWSCredentials(awsAccessKey, awsSecretKey);

        RestS3Service s3Service = new RestS3Service(awsCredentials);

        S3Bucket[] myBuckets = s3Service.listAllBuckets();
        println("How many buckets to I have in S3? " + myBuckets.length);

    }


}

When I execute this code I get error as :

java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: No suitable ClassLoader found for grab
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
    at groovy.grape.GrapeIvy.chooseClassLoader(GrapeIvy.groovy:182)
    at groovy.grape.GrapeIvy$chooseClassLoader.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
    at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:249)
    at groovy.grape.Grape.grab(Grape.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
    at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214)
    at s3_read.<clinit>(s3_read.groovy)
Exception in thread "main" 

I have just started learning and using groovy so I don't if there is any syntax error in my code and if yes then how to resolve this? Can anyone point me to the mistake I am doing and how to correct it?

user2966197
  • 2,793
  • 10
  • 45
  • 77

1 Answers1

0

I was able to get through this error by first executing the code with @Grab command on and let it go to error and since it already downloaded the jars so next time run it by commenting out the @Grab. More relevant answer is at https://youtrack.jetbrains.com/issue/IDEA-103435#comment=27-657787

user2966197
  • 2,793
  • 10
  • 45
  • 77