Question

I tried to configure antlr and netbeans with build xml, i followed the http://wiki.netbeans.org/AntlrInNetBeansJavaApplication tutorial, but when i clean and build the project i get an error like

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

I set the classpath: SET CLASSPATH=.;c:\Users\BayDebrecen\Downloads\antlr-4.2.2-complete.jar;%CLASSPATH%

my build xml:

<?xml version="1.0" encoding="UTF-8"?>

Builds, tests, and runs the project MyAntlrProject.

<target name="-pre-compile" depends="antlr">
</target>

<target name="init-antlr">
    <!-- Full path to Antlr jar -->
    <property name="antlr.jar" location="c:\\Users\\BayDebrecen\\Downloads\\antlr-4.2-complete.jar"/>
    <!-- Grammar path -->
    <property name="antlr.grammar" location="src\\myantlrproject\\MyGrammar.g"/>
</target>

<target name="antlr" depends="init-antlr" unless="up-to-date">
    <!-- Compiling grammar -->
    <java classname="org.antlr.Tool"  fork="true">
        <arg value="${antlr.grammar}"/>
        <classpath path="${antlr.jar}"/>
    </java>        
</target>

How can I correctly compile and run my generated class?

Was it helpful?

Solution

ANTLR3's Tool was in the package org.antlr, but with ANTLR4, it is in the package org.antlr.v4.

So, change:

classname="org.antlr.Tool" 

into:

classname="org.antlr.v4.Tool" 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top