Pratik
Pratik

Reputation: 978

Eclipse not recognizing generated class

I have used Maven plugin to generate classes in my project. However even after trying padding it explicitly from project build path, eclipse is unable to recognize it. It says,

"AbcBaseListener cannot be resolved to a type"

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here Project auto build is also ON.

Upvotes: 0

Views: 2171

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328556

Check 2 things:

1) The important hint here is "class folder". Eclipse expects .class files in there, source code will be ignored.

To fix this, add this plugin to your POM:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>target/generated-sources/</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

and update the project (Maven -> Update ...).

The other option would be to manually add another source folder to the build path but that will get lost whenever m2e updates the project configuration from the POM.

2) Make sure your generated files are having package names;

Use below code inside your g4 file after grammar Abc;

@header {
    package antlr4;
}

Upvotes: 2

Related Questions