Francesco
Francesco

Reputation: 317

Eclipse > Java > open linked resources sources (.java instead of .class )?

I have 2 projects, A and B

project B have in his build path > libraries the class folder of A (Eclipse also recognized that there is a "Source attachment" and added it.

Both A and B are in the same workspace.

When I Ctrl + click into a function of project A referenced into a file of B Eclipse open the .class file of A. But if I need to edit the .java version of that file I must manually look for the filename in project A and open it from project explorer.

There isn't an easier way to go from a linked resource to -> .java file of his source or to go from .class to .java in easier way than manually expand folders and open the file?

Upvotes: 8

Views: 6377

Answers (4)

utkarshp
utkarshp

Reputation: 91

Go to Project->Properties->Java Build Path.

In Order and Export keep all the src files on top and selected.

Eclipse will now pick .java over .class files

Upvotes: 9

milosmns
milosmns

Reputation: 3793

Another case solution:

One neat feature of Eclipse (and other IDEs) is that you can hold CTRL and click on a function or variable to go to its definition.

A problem which may occur in Eclipse is that it opens the .class file (the compiled file) instead of opening the .java file when you do this. This is probably caused by the order of the entries in the .classpath file.

Go to your project directory and open the .classpath file. Move all entires of type classpathentry with attribute kind="src" to the top of the file (or at least above any entries with kind "output").

Restart Eclipse and the problem should be fixed.

Found on this page

Upvotes: 5

oers
oers

Reputation: 18714

You can use Ctrl+Shift+T to open a search Dialog.

But you should add B as a dependent project of A (and remove it from the classpath).

enter image description here

Upvotes: 7

pablochan
pablochan

Reputation: 5715

Remove project A from "build path > libraries" and put it in "build path > projects".

Upvotes: 4

Related Questions