uwol / proleap-cobol-parser

ProLeap ANTLR4-based parser for COBOL
MIT License
134 stars 73 forks source link

Issue in generating AST #97

Open sundar-sarvam opened 11 months ago

sundar-sarvam commented 11 months ago
Exception in thread "main" java.lang.NoClassDefFoundError: org/antlr/v4/runtime/tree/ParseTree
        at CobolParserDemo.parseCobolFile(App.java:27)
        at CobolParserDemo.main(App.java:14)
Caused by: java.lang.ClassNotFoundException: org.antlr.v4.runtime.tree.ParseTree
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        ... 2 more

The issue seems to be pointing that the ANTLR4 library is not available to be referenced.

I have added Proleap-cobol-parser.4.0.0.jar as "Referenced libraries" to the Java project (not Maven project). It was created after successfully building the proleap-cobol-parser repo locally. I think I need to add Proleap-cobol-parser-sources.jar as "Referenced libraries" as well but when I add it in Visual Studio Code, it's not getting added.

Is this a common issue and any workaround to it?

uwol commented 11 months ago

Hi @sundar-sarvam ,

the problem is that in your setup the ANTLR library is not on the class path as a dependency.

This project uses Maven for dependency management. When importing the code into Eclipse or Intellij IDEA, those IDEs should automatically recognize the Maven pom.xml and fetch all dependencies, including ANTLR as configured in here.

To my understanding you try to use Visual Studio Code for Java here -> support for larger Maven projects in Visual Studio Code was problematic for me in the past -> I definitely recommend Intellij or Eclipse!

Best Ulrich

sundar-sarvam commented 11 months ago

Thanks @uwol . I realised that for some reason Proleap-cobol-parser-sources.jar wasn't importable (tried different ways: created a java project, maven project and tried to add dependencies, copied the .jars to lib directory of the workspace, etc. but didn't work). At the end, I download jar for ANTLR4 and slf4j-api separately and then the ANTLR issue got resolved.

Screenshot 2023-08-21 at 7 37 27 PM

But now I am facing the below warning:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Level Number: 1

On referring this link: https://www.slf4j.org/codes.html#StaticLoggerBinder, it seems to not be an issue (right?).

I am new to Java but very comfortable with VSC, so can't change IDE so easily. I am able to successfully run this example: https://stackoverflow.com/questions/49353699/getting-static-function-call-graph-of-a-cobol-program-in-java and Hello world example using the above dependency workaround.

uwol commented 11 months ago

Yes, Logback is missing from your dependencies.

sundar-sarvam commented 11 months ago
Screenshot 2023-08-21 at 7 54 07 PM

On the left you see that I have include logbook and junit dependency as well but I still get the above warning: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"..