Nov 19, 2010

What is Caught: java.lang.NoSuchMethodError: antlr.ASTFactory.setASTNodeClass(Ljava/lang/Class;)V?

Are you trying to run a groovy script and keep on getting the error "Caught: java.lang.NoSuchMethodError: antlr.ASTFactory.setASTNodeClass(Ljava/lang/Class;)V"?
I was in that boat a couple of days back and was wondering what was causing this issue since I had been using groovy for the past few months without any issues.

What I was doing was trying to run a groovy script at the home directory of a new server. I was using groovy 1.7.0 version and kept on getting the above error irrespective of the script that I ran! I was trying to run it from command line from my home directory on an unix server using
 ~/software/groovy-1.7.0/bin/groovy <groovy-script name.groovy>

On exploring a bit,I was able to see that the "NoSuchMethodError" error had popped in from the antlr library. So, I went into the \lib directory within the groovy folder and looked into the antlr library that was present.

I noticed that there were 2 antlr libraries that were present. They were
antlr-2.7.7.jar and antlr.jar. I was of the opinion that the groovy program would have got confused with the existence of 2 different instances of all classes within the 2 different antlr library present within the groovy folder. Hence, I deleted the antlr.jar and retained the antlr-2.7.7.jar and tried running the script.

The scripts started to run without any issues thereafter!

1 comment:

  1. If you'd like to learn more about java technology visit our Geek's Guide on Java training.

    There you'll find recorded webcasts, videos, white papers, and free tools that can teach you

    all you need to know about this cool and often overlooked technology...

    java training