Eclipse:资源不在Java项目的构建路径上

时间:2021-12-16 11:24:43

I have been given a Source Folder (src) of a Java Project. I have created a .project file, kept it inside that folder and imported that Project into Eclipse 3.6 through the Import Existing Projects into Workspace Option and added required jars to it.

我获得了一个Java项目的源文件夹(src)。我已经创建了一个. Project文件,并将其保存在该文件夹中,并通过将现有项目导入到Workspace选项中导入到Eclipse 3.6中,并向其中添加所需的jar。

Now the Problem is that when ever i do a Call Hierarchy on a Project , It displays a Alert box Saying "The resource is not on the build path of a java project"

现在的问题是,当我在项目上执行调用层次结构时,它会显示一个警告框,说“资源不在java项目的构建路径上”

Could anybody please let me know how to resolve this ?

谁能告诉我怎么解决这个问题吗?

Please see the image here

请看这里的图片

Eclipse:资源不在Java项目的构建路径上

Thanks

谢谢

11 个解决方案

#1


62  

You can add the src folder to build path by:

您可以添加src文件夹来构建路径:

  1. Select Java perspective.
  2. 选择Java透视图。
  3. Right click on src folder.
  4. 右键单击src文件夹。
  5. Select Build Path > Use a source folder.
  6. 选择Build Path >使用源文件夹。

And you are done. Hope this help.

和你做。希望这个有帮助。

EDIT: Refer to the Eclipse documentation

编辑:请参考Eclipse文档

#2


10  

Recently I met a similar problem. when importing a project without .project, a default empty .project generated without builders. here is an example to make it work.

最近我遇到了一个类似的问题。当导入没有.project的项目时,没有生成器生成的默认空的.project。这里有一个让它工作的例子。

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

#3


8  

I found similar issue and fixed it by correcting .project file. For java project .project file must have below tag within natures

我发现了类似的问题并通过修改.project文件进行了修复。对于java项目。项目文件必须在属性中有以下标记。

org.eclipse.jdt.core.javanature

org.eclipse.jdt.core.javanature


Example of complete .project file

完整的.project文件示例

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>SampleProjectName</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.maven.ide.eclipse.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>oracle.eclipse.tools.weblogic.sharedLibraryFrameworkValidator</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

#4


8  

I am trying to set up a dynamic web project using eclipse and its maven plugin. I am selecting maven-archetype-webapp and facing the same problem (which I run onto when trying to automatically produce getters and setters for some attributes).

我正在尝试使用eclipse及其maven插件建立一个动态web项目。我正在选择maven- prototype -webapp,并面对同样的问题(我在尝试自动生成一些属性的getter和setter时遇到了这个问题)。

My way around this was to right-click on the project, select Build Path --> Configure Build Path and then remove a weird exclusion filter "Excluded:**" which I found under the entry /src/main/resources.

我的方法是右键单击项目,选择Build Path——>配置构建路径,然后删除我在条目/src/main/resources下找到的一个奇怪的排除过滤器“排除:**”。

#5


5  

It means your project isn't on the compilation path of Eclipse.If after the accepted answer problem persists then you need to first place that project in the compilation path. For that you need to import the project again in your workspace, after that it will work fine.

这意味着您的项目不在Eclipse的编译路径上。如果在已接受的答案问题持续之后,您需要将该项目放在编译路径的首位。为此,您需要在工作区中再次导入项目,之后它将正常工作。

Similar problem came to me and I did whatever I have told you and it worked for me.

类似的问题出现在我身上,我做了我告诉你的一切,这对我很有效。

#6


2  

In my case, I had a java project containing many subfolders, each containing its own src folder.

在我的例子中,我有一个java项目,其中包含许多子文件夹,每个子文件夹包含它自己的src文件夹。

project
-subfolder
--src/main/java
-subfolder2
--src/main/java

There was no options available when I used the Build Path -> right click option, as outlined by other responses.

当我使用构建路径->右击选项时,没有可用的选项,这是其他响应所描述的。

I had to go to Project -> Properties -> Project Facets and click convert to faceted project.

我必须去项目->属性->项目facet然后点击转换到分面项目。

Then I got all the src folders added to the build path.

然后我将所有src文件夹添加到构建路径中。

#7


1  

All you got to do is move your Project folder under the Src, that is all, it is done. Let me know if any more questions.

你所要做的就是把你的项目文件夹移到Src下面,就是这样了。如果还有问题,请告诉我。

#8


1  

Refactor the name of the folder src/main/resource to src/main/java.

将文件夹src/main/resource的名称重构为src/main/java。

Right click the project > Build Path > Use Source Folder.

右键单击项目>构建路径>使用源文件夹。

#9


0  

Looks like you created your Java class under src/main/resources instead of src/main/java

看起来您是在src/main/resources而不是src/main/ Java下创建Java类的

#10


0  

If you imported a project from external source with pom.xml after import, go to Project->Properties->Maven and enable Java EE - This will resolve the error

如果您使用pom从外部源导入项目。导入xml后,转到Project->Properties->Maven并启用Java EE——这将解决错误

#11


0  

Using Eclipse Oxygen with a multimodule maven project make sure you're not editing the file in the maven parent project.

使用Eclipse Oxygen与多模块maven项目一起使用,确保您没有编辑maven父项目中的文件。

This caused the "Open Declaration', 'Open Type Hierarchy' and 'Open Call Hierarchy' to show the dreaded dialog in question. It would even mess with the autocomplete.

这导致了“开放声明”、“开放类型层次结构”和“开放调用层次结构”显示了令人担忧的对话框。它甚至会扰乱自动完成。

#1


62  

You can add the src folder to build path by:

您可以添加src文件夹来构建路径:

  1. Select Java perspective.
  2. 选择Java透视图。
  3. Right click on src folder.
  4. 右键单击src文件夹。
  5. Select Build Path > Use a source folder.
  6. 选择Build Path >使用源文件夹。

And you are done. Hope this help.

和你做。希望这个有帮助。

EDIT: Refer to the Eclipse documentation

编辑:请参考Eclipse文档

#2


10  

Recently I met a similar problem. when importing a project without .project, a default empty .project generated without builders. here is an example to make it work.

最近我遇到了一个类似的问题。当导入没有.project的项目时,没有生成器生成的默认空的.project。这里有一个让它工作的例子。

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

#3


8  

I found similar issue and fixed it by correcting .project file. For java project .project file must have below tag within natures

我发现了类似的问题并通过修改.project文件进行了修复。对于java项目。项目文件必须在属性中有以下标记。

org.eclipse.jdt.core.javanature

org.eclipse.jdt.core.javanature


Example of complete .project file

完整的.project文件示例

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>SampleProjectName</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.maven.ide.eclipse.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>oracle.eclipse.tools.weblogic.sharedLibraryFrameworkValidator</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

#4


8  

I am trying to set up a dynamic web project using eclipse and its maven plugin. I am selecting maven-archetype-webapp and facing the same problem (which I run onto when trying to automatically produce getters and setters for some attributes).

我正在尝试使用eclipse及其maven插件建立一个动态web项目。我正在选择maven- prototype -webapp,并面对同样的问题(我在尝试自动生成一些属性的getter和setter时遇到了这个问题)。

My way around this was to right-click on the project, select Build Path --> Configure Build Path and then remove a weird exclusion filter "Excluded:**" which I found under the entry /src/main/resources.

我的方法是右键单击项目,选择Build Path——>配置构建路径,然后删除我在条目/src/main/resources下找到的一个奇怪的排除过滤器“排除:**”。

#5


5  

It means your project isn't on the compilation path of Eclipse.If after the accepted answer problem persists then you need to first place that project in the compilation path. For that you need to import the project again in your workspace, after that it will work fine.

这意味着您的项目不在Eclipse的编译路径上。如果在已接受的答案问题持续之后,您需要将该项目放在编译路径的首位。为此,您需要在工作区中再次导入项目,之后它将正常工作。

Similar problem came to me and I did whatever I have told you and it worked for me.

类似的问题出现在我身上,我做了我告诉你的一切,这对我很有效。

#6


2  

In my case, I had a java project containing many subfolders, each containing its own src folder.

在我的例子中,我有一个java项目,其中包含许多子文件夹,每个子文件夹包含它自己的src文件夹。

project
-subfolder
--src/main/java
-subfolder2
--src/main/java

There was no options available when I used the Build Path -> right click option, as outlined by other responses.

当我使用构建路径->右击选项时,没有可用的选项,这是其他响应所描述的。

I had to go to Project -> Properties -> Project Facets and click convert to faceted project.

我必须去项目->属性->项目facet然后点击转换到分面项目。

Then I got all the src folders added to the build path.

然后我将所有src文件夹添加到构建路径中。

#7


1  

All you got to do is move your Project folder under the Src, that is all, it is done. Let me know if any more questions.

你所要做的就是把你的项目文件夹移到Src下面,就是这样了。如果还有问题,请告诉我。

#8


1  

Refactor the name of the folder src/main/resource to src/main/java.

将文件夹src/main/resource的名称重构为src/main/java。

Right click the project > Build Path > Use Source Folder.

右键单击项目>构建路径>使用源文件夹。

#9


0  

Looks like you created your Java class under src/main/resources instead of src/main/java

看起来您是在src/main/resources而不是src/main/ Java下创建Java类的

#10


0  

If you imported a project from external source with pom.xml after import, go to Project->Properties->Maven and enable Java EE - This will resolve the error

如果您使用pom从外部源导入项目。导入xml后,转到Project->Properties->Maven并启用Java EE——这将解决错误

#11


0  

Using Eclipse Oxygen with a multimodule maven project make sure you're not editing the file in the maven parent project.

使用Eclipse Oxygen与多模块maven项目一起使用,确保您没有编辑maven父项目中的文件。

This caused the "Open Declaration', 'Open Type Hierarchy' and 'Open Call Hierarchy' to show the dreaded dialog in question. It would even mess with the autocomplete.

这导致了“开放声明”、“开放类型层次结构”和“开放调用层次结构”显示了令人担忧的对话框。它甚至会扰乱自动完成。