Error: could not find or load the main class org.antlr.Tool

I start both in java and in ANTLR. I am trying to use ANTLR in the Netbeans IDE. I tried to run a sample example and followed all the important steps necessary to set an environment variable, including a jar file and modifications to built.xml.

But when I try to clean and create my application, I get the following errors:

Error: Could not find or load main class org.antlr.Tool Java Result: 1 Created dir: ../NetBeansProjects/AntlrTestApp/build/empty Created dir: ../NetBeansProjects/AntlrTestApp/build/generated-sources/ap-source-output Compiling 1 source file to ../NetBeansProjects/AntlrTestApp/build/classes ../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:24: error: cannot find symbol grammarLexer lexer = new grammarLexer(input); symbol: class grammarLexer location: class AntlrTestApp ../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:24: error: cannot find symbol grammarLexer lexer = new grammarLexer(input); symbol: class grammarLexer location: class AntlrTestApp ../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:26: error: cannot find symbol grammarParser parser = new grammarParser(tokens); symbol: class grammarParser location: class AntlrTestApp ../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:26: error: cannot find symbol grammarParser parser = new grammarParser(tokens); symbol: class grammarParser location: class AntlrTestApp ../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:29: error: cannot find symbol Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); symbol: class Main location: class AntlrTestApp ../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:31: error: cannot find symbol Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); symbol: class Main location: class AntlrTestApp 6 errors ../NetBeansProjects/AntlrTestApp/nbproject/build-impl.xml:603: The following error occurred while executing this line: ../NetBeansProjects/AntlrTestApp/nbproject/build-impl.xml:244: Compile failed; see the compiler error output for details. BUILD FAILED (total time: 1 second) 

I tried this from the last 2-3 days and looked for all possible solutions, but nothing worked for me.

+4
source share
2 answers

It looks like you are trying to automatically generate a parser from ANTLR 3 grammar during Ant build. The following Ant script example shows an example of this, which includes the following functions:

  • If necessary, it automatically downloads the necessary version of the ANTLR 3 tool, so you do not need to include the file in the original control or manually configure your build machines.
  • Automatically finds all .g files in the specified source folders, so you do not need to edit the assembly every time you add a grammar.
  • Complete processing of current checks for maximum incremental build performance.

https://github.com/antlr/antlr4/blob/master/build.xml

+2
source

I had a similar error. Using the antlr-x-complete.jar distribution solved my problem.

0
source

All Articles