简体   繁体   English

Eclipse无法识别生成的类

[英]Eclipse not recognizing generated class

I have used Maven plugin to generate classes in my project. 我已经使用Maven插件在我的项目中生成类。 However even after trying padding it explicitly from project build path, eclipse is unable to recognize it. 但是,即使在尝试从项目构建路径显式填充它之后,eclipse也无法识别它。 It says, 它说,

"AbcBaseListener cannot be resolved to a type" “ AbcBaseListener无法解析为类型”

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明 Project auto build is also ON. 项目自动构建也处于启用状态。

Check 2 things: 检查两件事:

1) The important hint here is "class folder". 1)这里的重要提示是“类文件夹”。 Eclipse expects .class files in there, source code will be ignored. Eclipse期望其中存在.class文件,源代码将被忽略。

To fix this, add this plugin to your POM: 要解决此问题,请将此插件添加到您的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 ...). 并更新项目(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. 另一个选择是手动将另一个源文件夹添加到构建路径,但是每当m2e从POM更新项目配置时,该文件夹都会丢失。

2) Make sure your generated files are having package names; 2)确保您生成的文件具有程序包名称;

Use below code inside your g4 file after grammar Abc ; 语法Abc之后,在g4文件中使用以下代码;

@header {
    package antlr4;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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