Closed gilcesarf closed 4 years ago
The initial idea I have to fix the problem is to add a parameter to the method getClassLoader() and pass "/target/classes" or "/target/test-classes" if instantiating a Lexer/Parser or a GrammarInitializer. Will take a closer look at the code to check if its a good approach.
Already fixed the issue. Waiting on PR to close issue
I have created a new scenario and configured a GrammarInitializer implemented inside my src/test/java root. A ClassNotFound exception was raised as at the end.
I investigated the problem and it is caused because of this snippet inside com.khubla.antlr.antlr4test.Scenario class:
This is the code used to get a classloader to load the Lexer and Parser. It points explicitly to "/target/classes". But when the GrammarInitializer is put inside /src/test/java, the corresponding .class gets compiled to "/target/test-classes", so it cannot be found.
Until I fix this, a possible workaround is to put the GrammarInitializer implementation inside the main source project root: src/main/java
This workaround solved the ClassNotFoundException. Its drawback is that GrammarInitializer class would be distributed with the .jar of the project.