Eclipse - How to give dependency between projects?

2019-01-14 11:33发布

问题:

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.

Thanks in advance.

回答1:

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.

Instead open the project properties of 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".

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.



回答2:

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.

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.