Eclipse - 如何在项目之间提供依赖?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10553677/
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
Eclipse - How to give dependency between projects?
提问by Vaandu
I have two java projects in eclipse. Second one is using first one's jar. When I try to navigate to first one's class from second one, it opens .class
of that file. But I want to open the first one project file. Please help.
我在 eclipse 中有两个 java 项目。第二个是使用第一个的罐子。当我尝试从第二个班级导航到第一个班级时,它会打开.class
该文件。但我想打开第一个项目文件。请帮忙。
Thanks in advance.
提前致谢。
回答by Robert
If you want to link your second project with your first project, don't add the first project in form of a JAR file to the second.
如果要将第二个项目与第一个项目链接,请不要将第一个项目以 JAR 文件的形式添加到第二个项目中。
Instead open the project propertiesof the second project and select "Java Build Path". On the right side on the "Projects" tab you can add your first project as "required project on the build path".
而是打开第二个项目的项目属性并选择“ Java Build Path”。在“项目”选项卡的右侧,您可以将您的第一个项目添加为“构建路径上的必需项目”。
The class files of project 1 are now added to the class path of project 2. And if you click on a class name you directly get to the source code.
项目 1 的类文件现在被添加到项目 2 的类路径中。如果您单击类名,您将直接进入源代码。
回答by Nagendra U M
Ideally, the JAR of the first project would appear under the "Referenced Libraries" of the second project. Right-click on that JAR, and choose Properties -> Java Source Attachment. Provide a variable that links to the source files of this JAR.
理想情况下,第一个项目的 JAR 将出现在第二个项目的“参考库”下。右键单击该 JAR,然后选择 Properties -> Java Source Attachment。提供链接到此 JAR 源文件的变量。
Alternatively, install a decompiler plugin (see jd-eclipse) which will decompile class files when you navigate them in Eclipse, so that you can see the source.
或者,安装一个反编译器插件(参见jd-eclipse),当您在 Eclipse 中导航它们时,它将反编译类文件,以便您可以看到源代码。