简体   繁体   中英

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"

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明 Project auto build is also ON.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM