27

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.

Vaandu
  • 4,857
  • 12
  • 49
  • 75
  • 1
    http://stackoverflow.com/questions/10090829/how-to-reference-a-different-java-project-in-eclipse – William Feb 22 '17 at 00:48

3 Answers3

36

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.

Robert
  • 39,162
  • 17
  • 99
  • 152
  • I have an Eclipse project generated from an SBT project (using the plugin), which already set up the dependency; but Eclipse still cannot see ProjX from ProjY (ProjY is set up to depend on ProjX). Any ideas? – Erik Kaplun Nov 16 '13 at 02:41
  • 1
    when i am deploying my project to the server it throws an exception `The import util cannot be resolved DataLayer cannot be resolved` even i also added my project in deployment assembly as well, what is still i'am doing wrong – Sarz Mar 25 '14 at 08:01
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.

Nagendra U M
  • 601
  • 2
  • 6
  • 16
0

Make one project in Eclipse depend on another so that the dependencies are available in the indexer

Tested on Eclipse IDE for C/C++ Developers 2022-09 (4.25.0) on Linux Ubuntu 18.04.

For C++, right-click on the project which depends on another project. Go to "Properties" --> Project References --> check the box next to the project whose files and resources you'd like to be available in the project you are editing --> click "Apply and Close".

The indexed resources in the project next to the box you just checked (glib in the screenshot below) are now available to the project whose properties you just edited! This means if you Ctrl + Click a variable which is defined in the project you are editing, your indexer will now jump to its definition even if it lies in the referenced project (glib in this case)!

Screenshot:

enter image description here

Done!


Old and wrong answer (but may be helpful for adding includes to your project)

For C++, right-click on the project which depends on another project. Go to "Properties" --> C/C++ Include Paths and Symbols --> click "Add Include Path from Workspace..." --> choose the project from your workspace which it depends on, and drill down into the folder of interest --> click "OK". Click "Apply and Close".

You've now made your project whose properties you just edited depend on the other project in such a way that the dependent project dir you just added will now be indexed!

enter image description here

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265