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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2206572/
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-09-10 19:10:13  来源:igfitidea点击:

Eclipse "this compilation unit is not on the build path of a java project"

eclipsesvn

提问by l245c4l

I can't get autocompletion to work on Eclipse.

我无法在 Eclipse 上使用自动完成功能。

I'm working on the project on svn. I set up project in Eclipse by going into

我正在 svn 上做这个项目。我通过进入在 Eclipse 中设置项目

File -> Import -> Checkout As a Project -> New Project Wizard.

文件 -> 导入 -> 作为项目签出 -> 新建项目向导。

I choose Enterprise Java Application and it's being downloaded. And everything seems to work fine except instead autocompletion working as I expect I get a popup dialog displaying the message

我选择 Enterprise Java Application 并且正在下载它。一切似乎都很好,除了自动完成工作,因为我期望我得到一个显示消息的弹出对话框

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

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

I've Googled it but everyone says that project must be Java project. But hey it is! What is the problem?

我用谷歌搜索过,但每个人都说该项目必须是 Java 项目。但是,嘿!问题是什么?

Update

更新

The catalog structure on svn looks like this:

svn 上的目录结构如下所示:

-Project_name
  -application
     -META-INF
       application.xml
       MANIFEST.MF
  +build
  +db
  +deploy
  +dist
  +lib
  +properties
  +script
  -src
     -META-INF
        someother.xml (datasource info)
        persistence.xml
        folder hierarchy with source files (should be package)
  -web
     some folders
          .
          .
     files
       .
       .
     -WEB-INF
        faces-config.xml
        jboss-web.xml
        web.xml
     build_win.xml

How do I tell Eclipse where the source files folder, application.xml and other configuration xml files are?

我如何告诉 Eclipse 源文件文件夹、application.xml 和其他配置 xml 文件的位置?

回答by redochka

When you have a multimodules maven project under a parent project, make sure you're not editing the file in the maven parent project.

当您在父项目下有一个多模块 Maven 项目时,请确保您没有在 Maven 父项目中编辑该文件。

回答by Lenn Dolling

What I did to make one of my projects to check out properly is by

我所做的使我的一个项目正确检查是通过

1) Import your project from svn

1)从svn导入你的项目

      file-->import-->SVN-Checkout Projects From SVN

2) Find your Project and then in the "Check Out As" dialogue make sure you have the radio button selected "Check out as a project configured using the New Project Wizard"

2) 找到您的项目,然后在“签出为”对话框中确保选择了单选按钮“签出为使用新建项目向导配置的项目”

3) Go through regular steps.

3) 执行常规步骤。

The wizard pulls the project properly and then setups your eclipse....

该向导会正确拉取项目,然后设置您的 eclipse....

without using the wizard I find that all hell breaks loose.....

不使用向导,我发现所有的地狱都崩溃了.....

Hope this helps...

希望这可以帮助...

回答by Abhinav

This is what was missing in my .project file:

这是我的 .project 文件中缺少的内容:

    <projectDescription>
        ...
        <buildSpec>
            <buildCommand>
                <name>org.eclipse.jdt.core.javabuilder</name>
                <arguments>
                </arguments>
            </buildCommand>
        </buildspec>
        ...
        ...
        ...
        <natures>
            <nature>org.eclipse.jdt.core.javanature</nature>
            <nature>org.eclipse.m2e.core.maven2Nature</nature>
        </natures>
        ...
    </projectDescription>

回答by adam

I have this issue from time-to-time and often it's because the project wasn't marked as a java project. You can change this by going to the properties for the project > Project Facets > and selecting java. You may then need to properly configure that project, but this is probably part of the problem

我不时遇到这个问题,通常是因为该项目未标记为 Java 项目。您可以通过转到项目的属性 > Project Facets > 并选择 java.ini 来更改此设置。然后您可能需要正确配置该项目,但这可能是问题的一部分

回答by Erandi

I also had this problem after converting my java project into a maven project. I solved it as follows:

将我的 java 项目转换为 maven 项目后,我也遇到了这个问题。我是这样解决的:

Right click on your project ->Project Facets -> click on Java, then Apply.

右键单击您的项目 -> Project Facets -> 单击 Java,然后单击应用。

回答by Tommy Giovanelli

I might be picking up the wrong things from so many comments, but if you are using Maven, then are you doing the usual command prompt build and clean?

我可能会从这么多评论中找出错误的内容,但是如果您使用的是 Maven,那么您是否正在执行通常的命令提示符构建和清理?

Go to cmd, navigate to your workspace (usually c:/workspace). Then run "mvn clean install -DskipTests"

转到 cmd,导航到您的工作区(通常是 c:/workspace)。然后运行“mvn clean install -DskipTests”

After that run "mvn eclipse:eclipse eclipse:clean" (don't need to worry about piping).

之后运行“mvn eclipse:eclipse eclipse:clean”(不需要担心管道问题)。

Also, do you have any module dependencies in your projects?

另外,您的项目中是否有任何模块依赖项?

If so, try removing the dependencies clicking apply, then readding the dependencies. As this can set eclipse right when it get's confused with buildpath sometimes.

如果是这样,请尝试删除依赖项,单击应用,然后阅读依赖项。因为这可以在 eclipse 有时与 buildpath 混淆时正确设置它。

Hope this helps!

希望这可以帮助!

回答by yyy

Did you have your .project file in your folders?

您的文件夹中有 .project 文件吗?

I got the same problem. Than i realized that I didn't have the .project file.

我遇到了同样的问题。比我意识到我没有 .project 文件。

回答by Alex

I did copy the .classpath and .project from another project and adjusted the values properly.

我确实从另一个项目中复制了 .classpath 和 .project 并正确调整了值。

Close the project before editing those files, when you are sure they reflect the reality (your reality anyway), re-open the project in Eclipse.

在编辑这些文件之前关闭项目,当您确定它们反映了现实(无论如何都是您的现实)时,在 Eclipse 中重新打开项目。

The workspace is rebuilt and all should work from then on.

工作区被重建,从那时起一切都应该工作。

回答by Huub

in my case it's a maven project

就我而言,这是一个 Maven 项目

delete the project from eclipse leaving the sources close eclipse delete from filesystem

从 eclipse 中删除项目离开源代码 close eclipse 从文件系统中删除

.target/ .classpath .project .settings/ open eclipse Again Import Maven Projects

.target/ .classpath .project .settings/再次打开eclipse导入Maven项目

This solved the problem

这解决了问题

回答by Rami C

You may want to try running eclipse with the -clean startup option - it tries re-building eclipse's metadata of the workspace.

您可能想尝试使用 -clean 启动选项运行 eclipse - 它会尝试重新构建 eclipse 的工作区元数据。