Eclipse Oxygen 此编译单元不在 java 项目的构建路径上

Eclipse Oxygen This compilation unit is not on build path of java project

我已经使用 Maven Archetype 创建了一个 Kafka Streams 项目:

mvn archetype:generate \
-DarchetypeGroupId=org.apache.kafka \
-DarchetypeArtifactId=streams-quickstart-java \
-DarchetypeVersion=1.0.0 \
-DgroupId=streams.examples \
-DartifactId=streams.examples \
-Dversion=0.1 \
-Dpackage=myapps

编译和运行程序:

> mvn clean package
> mvn exec:java -Dexec.mainClass=myapps.Pipe

程序运行良好。

然而,当我编辑代码并尝试 Ctrl+Space 时,我收到 Cannot perform operation 错误:

This compilation unit is not on build path of java project.

见下图:

就运行

mvn eclipse:eclipse

在项目目录中并在 eclipse 中刷新你的项目:File -> Refresh