我获取的资源不在项目的构建路径上
当我尝试“组织导入”或尝试访问任何类属性时,我得到了资源不在项目的构建路径上。 我正在使用 ant 构建我的项目。我尝试在 javabuilpath -> 中配置我的构建路径项目,但它没有向我显示我的 src 文件夹。由于同样的原因,我无法使用快速辅助(ctrl + 空格)和类相关属性 当我编写代码时,它也没有显示任何语法错误。
请帮我。
谢谢
I am getting The resource is not on the buildpath of the project when I am trying to "Organize imports" or trying to access any class properties.
I am building my project with ant.I tried to configure my buildpath in javabuilpath -> Projects but it is not showing me my src folder there.I am not able to use quick assist (ctrl + space) and class related properties because of the same reason
and it does not show me any syntax errors also while i am writing my code.
please help me.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我自己刚刚遇到这个问题,这很令人困惑。当您尝试将 Java 文件视为 Java 文件时,您会在很多不同的地方得到它,但 Eclipse 尚未发现它实际上是项目中的一个类。它不知道的原因(或者在我的情况下它不知道的原因)是因为该目录尚未被标记为项目的源目录。因此,您需要告诉项目配置该文件位于保存源文件的目录中。操作方法如下:
打开项目的属性。
在“Java 构建路径”下,单击“源”选项卡。
单击“添加文件夹...”
查找包含无法识别的 java 文件的文件夹。 (在我的
如果是 test->Java)
在文件夹旁边打勾。 (我只用“java”来表示,而不是用
“测试”,因为测试文件夹包含许多其他内容。)
单击“确定”,再次单击“确定”,也许刷新,您应该可以
继续。
I just hit this problem myself, and it's baffling. You get it in a bunch of different places as you try and treat a Java file as, you know, a Java file but Eclipse hasn't figured out that it's actually a class within your project. The reason it doesn't know (or the reason it didn't know in my case) was because the directory hasn't been marked as a source directory for the project. So you need to tell the project configuration that the file is in a directory that holds source files. Here's how:
Open your project's properties.
Under "Java Build Path", click on the "Source" tab.
Click "Add Folder..."
Find the folder where you have the unrecognized java file. (In my
case it was test->Java)
Put a check by the folder. (I put it only by "java" and not by
"test" given that the test folder holds a lot of other stuff.)
Click ok, click OK again, perhaps refresh, and you should be good to
go.
您的 src 文件夹不应出现在 Java 构建路径 中 -> 项目选项卡。相反,它应该出现在来源选项卡下。
Your src folder shouldn't appear in the Java Build Path -> Projects tab. Rather, it should appear under Source tab.
尝试将类文件导入为外部 jar。
Try imorting the class files as external jar.
该文件使用什么图标?如果它是一个大纲,J eclipse 不会将该文件识别为项目的源文件。
如果是这样,您需要将包的父文件夹声明为源文件夹,即,如果路径看起来像“.../src/my/package/MyClass.java”,则“src”必须声明为源文件夹(右)单击->构建路径->用作源文件夹)
What icon is used for the file? If it is an outline J eclipse doesn't recognize the file as being a source file of the project.
If so, you need to declare the parent folder of your package a source folder, i.e. if the path looks like ".../src/my/package/MyClass.java" the "src" must be declared a source folder (right click -> Build Path -> Use as Source Folder)