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

发布于 2024-08-20 12:56:59 字数 897 浏览 8 评论 0原文

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

我正在 svn 上做这个项目。 在 Eclipse 中设置项目”

我通过进入“文件”->“ 导入->作为项目结账 ->新建项目向导。

我选择了企业Java应用程序。一切似乎都工作正常,除了自动完成功能没有像我预期的那样工作,而是出现一个显示消息的弹出对话框

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

我用 Google 搜索了一下,每个人都说该项目一定是一个 Java 项目,但它确实是!问题是什么?

更新

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

如何告诉 Eclipse 源文件文件夹、application.xml 和其他配置 xml 文件在哪里?

I can't get autocompletion to work in Eclipse.

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

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

I chose Enterprise Java Application. Everything seemed to work fine except instead of autocompletion working as I expected I got a popup dialog displaying the message

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

I've Googled it and everyone says that the project must be a Java project, but it is! What is the problem?

Update

The catalog structure on svn looks like this:

-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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(24

窝囊感情。 2024-08-27 12:56:59

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

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

ヤ经典坏疍 2024-08-27 12:56:59

为了使我的一个项目能够正确签出,我所做的就是:

1)从 svn 导入您的项目

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

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

3) 执行常规步骤。

向导正确地拉出项目,然后设置你的日食......

不使用向导我发现一切都乱了......

希望这有帮助......

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

1) Import your project from 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"

3) Go through regular steps.

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

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

Hope this helps...

谁对谁错谁最难过 2024-08-27 12:56:59

这是我的 .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>

This is what was missing in my .project file:

    <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>
追星践月 2024-08-27 12:56:59

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

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

梦忆晨望 2024-08-27 12:56:59

我在将java项目转换为maven项目后也遇到了这个问题。我解决如下:

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

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

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

昔梦 2024-08-27 12:56:59

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

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

Did you have your .project file in your folders?

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

み格子的夏天 2024-08-27 12:56:59

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

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

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

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

如果是这样,请尝试单击“应用”删除依赖项,然后读取依赖项。因为当 Eclipse 有时与构建路径混淆时,这可以正确设置 Eclipse。

希望这有帮助!

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?

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

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

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.

Hope this helps!

夏至、离别 2024-08-27 12:56:59

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

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

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

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

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

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

错々过的事 2024-08-27 12:56:59

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

从 Eclipse 中删除该项目,留下源代码
关闭日食
中删除

从文件系统.target/
.classpath
。项目
。设置/
打开日食
再次导入Maven项目

这解决了问题

in my case it's a maven project

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

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

This solved the problem

篱下浅笙歌 2024-08-27 12:56:59

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

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

浅忆 2024-08-27 12:56:59
mvn eclipse:eclipse

解决了我的问题

mvn eclipse:eclipse

solved my problem

居里长安 2024-08-27 12:56:59

这里是在 eclipse 中创建源文件夹的步骤。

  1. 右键单击项目并转到属性
  2. 从属性对话框中选择“Java Build Path”
  3. 选择源选项卡并检查源文件夹是否正确 如果不单击“删除”按钮以删除源文件夹,或单击“添加”按钮添加源文件夹。

您可以在配置构建路径选项的“顺序”和“导出”选项卡上控制源文件夹在项目中显示的顺序。

Here the steps for creating a source folder in eclipse.

  1. Right click on the project and go to properties
  2. Select "Java Build Path" from the properties dialog box
  3. Select the source tab and check that the source folders are correct if not click on the remove button to remove source folders, or the add button to add source folders.

You can control the order in which source folders appear in a project on order and export tab on the configure build path option.

仅此而已 2024-08-27 12:56:59

有同样的问题(但是使用 Maven)。原因是执行程序选择不正确:我的项目使用了 Maven 嵌入式安装中无法提供的全局设置。将其更改为外部(窗口 -> 首选项 -> Maven -> 安装)并解决了问题。

Had the same problem (but with Maven). The reason was incorrect choice of executor: my project used global settings that are not avilable from Embedded installation of Maven. Changed it to external (Window -> Preferences -> Maven -> Installations) and that fixed the problem.

新雨望断虹 2024-08-27 12:56:59

我所做的是从 svn 导入项目后,从工作区删除该项目并将其作为 Maven 项目从本地导入。然后在
首选项->maven->用户设置->在用户设置框中给出了settings.xml的路径,该路径将位于apache maven文件夹中-> conf->settings.xml

它为我解决了这个问题。

What i did is after importing the project from svn , deleted the project from workspace and imported it as a maven project from local . Then in
preferences->maven->usersettings->in usersettings box gave path of settings.xml which will be in apache maven folder-> conf->settings.xml

and it solved the issue for me.

请恋爱 2024-08-27 12:56:59

您的源文件应采用在Package Explorer视图中带有“package”图标的结构(在Window>Show View下的菜单中) > Package Explorer 或按 Ctrl+3 并输入 pack),如下所示:

Eclipse 中的 Java 项目< /a>

如果不是,请选择包含根包的文件夹(上图中的src),然后从上下文菜单中选择用作源文件夹(右键单击)。

Your source files should be in a structure with a 'package' icon in the Package Explorer view (in the menu under Window > Show View > Package Explorer or press Ctrl+3 and type pack), like this:

Java project in Eclipse

If they are not, select the folder containing your root package (src in the image above) and select Use as Source Folder from the context menu (right click).

海之角 2024-08-27 12:56:59

正如消息所述,该文件是否位于项目的 Java 构建路径上的某个位置(例如源文件夹)?

Like the message says, is the file somewhere on the project's Java Build Path (e.g. a Source folder)?

吃→可爱长大的 2024-08-27 12:56:59

有同样的问题。
解决方案:
上下文菜单 -> Maven->启用依赖管理

不知道为什么在签出时丢失了。

Had the same problem.
Solution:
Context menu -> Maven -> Enable dependency management

Do not know why that was lost, when checking out.

野味少女 2024-08-27 12:56:59

我发现由于我的文件(包括我的主类)位于 .src 文件夹之外而出现此错误。

I found that I was getting this error due to having my files, including my main class, outside of the .src folder.

沐歌 2024-08-27 12:56:59

对我有用的是从另一个项目复制 .settings/ 目录。

What worked for me was copping the .settings/ directory from another project.

虐人心 2024-08-27 12:56:59

从终端运行“mvn eclipse:eclipse”。

Run "mvn eclipse:eclipse" from terminal.

硪扪都還晓 2024-08-27 12:56:59

如果您是初学者(像我一样),解决方案可能很简单,只需确保您正在处理的文件的父文件夹是 Java 项目即可。

我犯了一个错误,简单地创建了一个 Java 文件夹,然后在该文件夹中创建了一个文件并期望它能够工作。如果您想避免此错误,该文件需要位于项目中。

If you're a beginner (like me), the solution may be as simple as making sure the parent folder that the file you're working in is a Java project.

I made the mistake of simply creating a Java folder, then creating a file in the folder and expecting it to work. The file needs to live in a project if you want to avoid this error.

始终不够 2024-08-27 12:56:59

导入由嵌套微服务组成的 Maven 项目后,我遇到了同样的问题。这就是我在 Eclipse 中解决该问题的方法:

  1. 右键单击项目
  2. 选择配置
  3. 选择“配置并检测嵌套项目”

I had same issue after importing maven project consisting of nested micro services. This is how I got it resolved in Eclipse:

  1. Right Click on Project
  2. Select Configure
  3. Select "Configure and Detect Nested Projects"
山有枢 2024-08-27 12:56:59

我通过在 Java Build Path 中添加项目解决了这个问题,

右键单击该项目 ->属性-> java构建路径->添加

enter图片描述在这里

I solved this by adding projects in Java Build Path

Right click on the project -> properties -> java build path -> Add

enter image description here

梦里的微风 2024-08-27 12:56:59

例如,如果有 4 个项目和一个根项目,请将其他子项目添加到根项目的构建路径中。如果没有选择构建路径,请将以下代码添加到.project 文件中。

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>rootProject</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
    </natures>
</projectDescription>

For example if there are 4 project and a root project, add the other child projects to build path of root project. If there is not selection of build path, add below codes to .project file.

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>rootProject</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
    </natures>
</projectDescription>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文