'Eclipse search opens up Java file that has no syntax highlight or source code link when the project is nested?
Situation::
- Trying to search and open up a Java file. In a nest project.
And so, we have the file here, these 2 files the exactly same file,
but, when the project is nested inside, Eclipse search opens up the file that has no syntax highlight or source code link (ie: unable to ctrl click on the code).
(ie: Eclipse opens up the Java file as if the Java file is not on a build path)
(though, if I search directly on that nested project, instead of on the parent project, then things are fine)
I have to manually open up the file in the Project Explorer, to get the file with syntax highlight or source code link.
Ask::
How can I let Eclipse directly open up the Java file with syntax highlight (when I search on the parent project)
(so that I dont need to manually search & click all the way through)?
Solution 1:[1]
You seems to be using Maven and you probably imported your project in Eclipse as Maven project.
The problem with Maven and Eclipse is that usually Maven project are split as project aggregator (a pom.xml
with only <module>
) which m2e will import: such aggregator project use a directory hierarchy.
Eclipse, on the other hand, does not scan files as file system file, but as project related file: that's the main reason for your duplicate. The child project being contained in its parent, the same file is shown twice because for Eclipse, these are two distinct path.
And since for the parent project, the file is simply a regular file it does not offer anything beside syntax highlighting.
You can:
- close each aggregator project one by one; for Eclipse, there are no really useful anyway.
- don't import them (and I wish m2e-core would suggest it).
You could also create a bug or vote for this one which seems related: https://bugs.eclipse.org/bugs/show_bug.cgi?id=533440
Note that this also affect other screen such as Show Resources (which is the subject of bug 533440).
Solution 2:[2]
The workaround I am using::
workaround 01
Find the files in the nest projects as I did before, then get the class name, then ctrl shift t
to search that class again.
- Cons:
- You have to manually copy and search the class name.
- There are possible other classes with same name (and you have to tell which one you want to go to).
- You will not be able to jump to the desire line.
workaround 02
Just search in the whole workspace
. And directly open in the file in the child-project (ignore the results from parent-project).
- Cons:
- Time consuming when search the whole workspace (though, you can terminate it when you get the desire files, hopefully no missing results when you do that).
- There are a lot duplicate / unnecessary results.
- You may not want to search the whole workspace.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | NoDataFound |
Solution 2 |