编译单元不在 Java 项目的构建路径上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19652313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 19:09:55  来源:igfitidea点击:

Compilation unit is not on the build path of a Java project

javaeclipsesvn

提问by Ssam

I joined an SVN server and checked out the source files a project from that server. In the Eclipse editors, when I hit Ctrl + Space, I got the following error message:

我加入了一个 SVN 服务器并从该服务器检出了一个项目的源文件。在 Eclipse 编辑器中,当我点击 时Ctrl + Space,我收到以下错误消息:

This compilation unit is not on the build path of a Java project

此编译单元不在 Java 项目的构建路径上

This compilation unit is not on the build path of a Java project

此编译单元不在 Java 项目的构建路径上

What should I do to solve this problem?

我应该怎么做才能解决这个问题?

回答by Rahul

Execute mvn eclipse:eclipse on command line and once the build is successful, refresh your project in eclipse. This resolve the issue.

在命令行上执行 mvn eclipse:eclipse ,一旦构建成功,在 eclipse 中刷新你的项目。这解决了问题。

回答by Raghav RV

Read this guide on how to use maven projects with eclipse

阅读本指南,了解如何在 Eclipse 中使用 Maven 项目

http://maven.apache.org/guides/mini/guide-ide-eclipse.html

http://maven.apache.org/guides/mini/guide-ide-eclipse.html

Taken from the above link :

取自上述链接:

Reason why you get that notice :

您收到该通知的原因:

Eclipse needs to know the path to the local maven repository. Therefore the classpath variable M2_REPO has to be set.

Eclipse 需要知道本地 maven 存储库的路径。因此必须设置类路径变量 M2_REPO。

Solution

解决方案

Execute the following command:

执行以下命令:

mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo

Restart your Eclipse IDE (if you already have it open) for this change to take effect. You can also define a new classpath variable inside eclipse: From the menu bar, select Window > Preferences. Select the Java > Build Path > Classpath Variables page

重新启动您的 Eclipse IDE(如果您已将其打开)以使此更改生效。您还可以在 eclipse 中定义一个新的类路径变量:从菜单栏中,选择 Window > Preferences。选择 Java > 构建路径 > 类路径变量页面

For Simple Projects :

对于简单项目:

If you have a simple java project which is made up of only one module, using eclipse is very simple. To generate the eclipse project files from your POM you execute the following command:

如果您有一个仅由一个模块组成的简单 java 项目,则使用 eclipse 非常简单。要从 POM 生成 eclipse 项目文件,请执行以下命令:

mvn eclipse:eclipse

mvn eclipse:eclipse

If you have created or checked out the project with eclipse, you only have to refresh the project in your workspace. Otherwise you have to import the project into your eclipse workspace (From the menu bar, select File >Import >Existing Projects into Workspace). In the latter case the project (directory) should not be located in your workspace, because eclipse might come into trouble, especially if you want to use eclipse as the scm client.

如果您已使用 eclipse 创建或检出项目,则只需刷新工作区中的项目即可。否则,您必须将项目导入您的 eclipse 工作区(从菜单栏中,选择 File >Import >Existing Projects into Workspace)。在后一种情况下,项目(目录)不应位于您的工作区中,因为 eclipse 可能会遇到麻烦,尤其是当您想使用 eclipse 作为 scm 客户端时。

For a more detailed explanation refer the above link.

有关更详细的解释,请参阅上面的链接。

回答by kumar

Import project as maven project.

将项目导入为 Maven 项目。

File-> import-> Maven-> Exiting Maven Project-> Next-> Root Directory-> Browse your project from Disk

File-> import-> Maven-> Exiting Maven Project-> Next-> Root Directory-> Browse your project from Disk

回答by R.J. Davis

Follow these steps:

按着这些次序:

  1. Right click project in Eclipse. Select to Run AsMaven build...
  2. In Goals add eclipse:eclipse
  3. Select Run
  4. Wait for build to finish
  5. Right click project in Eclipse. Select Refresh
  1. 在 Eclipse 中右键单击项目。选择Run AsMaven build...
  2. 在目标中添加 eclipse:eclipse
  3. 选择 Run
  4. 等待构建完成
  5. 在 Eclipse 中右键单击项目。选择Refresh