简体   繁体   English

无法使用eclipse在java中引用项目

[英]Can't reference project in java using eclipse

I've created a new project in java using eclipse.我已经使用 eclipse 在 java 中创建了一个新项目。

I've tried reference a project from the workspace to it - but when I try to write code using the referenced project interface it won't accept it.我尝试从工作区引用一个项目到它 - 但是当我尝试使用引用的项目接口编写代码时,它不会接受它。 Tried to jar the project and reference the jar - won't work.试图 jar 项目并引用 jar - 不起作用。

Another project - that I received with the project I try to reference - came already referenced and it works ok there.另一个项目 - 我收到的我尝试引用的项目 - 已经被引用并且在那里工作正常。

I did a simple reference using build path.我使用构建路径做了一个简单的参考。 Tried clean but it didn't help.试过干净,但没有帮助。 I'm on auto build.我正在自动构建。 Strange thing - eclipse won't recognize the attempt of using code from the referenced project - but if I press F3 on it - it will open the right source file.奇怪的事情 - eclipse 无法识别使用引用项目中的代码的尝试 - 但如果我按 F3 键 - 它会打开正确的源文件。

Check whether the workspace on which works has write permission in your file system or not.检查其工作的工作空间是否在您的文件系统中具有写入权限。

In case of jar archive make sure you have added that jar file in your class path using 'java buildpath'.如果是 jar 存档,请确保您已使用“java buildpath”在类路径中添加了该 jar 文件。 If you have added that reference to your project then it will definitely work.如果您已将该引用添加到您的项目,那么它肯定会起作用。

If an already referenced project works then according to me you have problem of access rights.如果一个已经引用的项目有效,那么根据我的说法,你有访问权限的问题。 You may not have permission to write/append your .classpath file.您可能无权写入/附加您的 .classpath 文件。

Hope you have performed below steps to add project reference.希望您已执行以下步骤来添加项目参考。

Right click project -> Build path -> Configure buildpath... -> Project tab -> Add... -> Then add project from current workspace右键单击项目 -> 构建路径 -> 配置构建路径... -> 项目选项卡 -> 添加... -> 然后从当前工作区添加项目

Years later, on Eclipse Version: 2022-03 (4.23.0) I've also had issues linking source code of dependent maven module projects.多年后,在 Eclipse 版本:2022-03 (4.23.0) 上,我在链接依赖 maven 模块项目的源代码时也遇到了问题。 I found parth's answer got me started but there's a few more details.我发现parth 的答案让我开始了,但还有更多细节。

Right click the parent project and select Build path -> Configure buildpath ...右键单击父项目并选择Build path -> Configure buildpath ...

  • on "Project" tab - use the Add button to add the eclipse project“项目”选项卡上 - 使用“添加”按钮添加 Eclipse 项目
  • on "Order and Export" tab - use the Up button to move the eclipse project higher than the JRE System Library and Maven Dependencies“订购和导出”选项卡上 - 使用向上按钮将 eclipse 项目移动到高于 JRE 系统库和 Maven 依赖项的位置

Upon returning to the code in the parent project and hitting F3 on a class name from the child project, eclipse will now bring me to the child project source code.返回父项目中的代码并在子项目的类名上按F3后,eclipse 现在会将我带到子项目源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM