Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - How to give dependency between projects?

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.

like image 393
Vaandu Avatar asked May 11 '12 14:05

Vaandu


People also ask

How do I add a project as a dependency of another project in Eclipse?

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.

How do I get dependencies in eclipse?

Right-click the project, then select "Properties", then "Java Build Path". The tabs "Projects" and "Libraries" list what the project depends on. Note that the "Order and Export" tab alllows you to have indirect dependencies. All the information here is saved in a file named .


2 Answers

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.

like image 153
Robert Avatar answered Sep 25 '22 17:09

Robert


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.

like image 23
Nagendra U M Avatar answered Sep 24 '22 17:09

Nagendra U M