Eclipse Maven showing multiple paths for the same file
Asked Answered
F

3

13

Is there any setting in Eclipse to show only the Maven project where the file resides?

I have different Maven projects which are modules of a parent Maven project:

projParent
   |-projWeb
   |-projModel
   |-projServices
   |-...

If I look for a file using "Open Resource" (using Ctrl + Shift + r) in Eclipse, it appears in many projects (E.g.: in projParent and in projWeb).

Is there any way to show only relevant folder where that file is actually resided in?

Franco answered 22/7, 2013 at 21:7 Comment(1)
This is a duplicate of #15065296, but the other question has a much better answer (set folders in parent projects as "derived").Sanburn
G
20

Try defining a Working Set that includes only the modules in which you want to search and then use that Working Set in the search.

EDIT

Actually I tried it and it just works perfectly by default in eclipse 4.3 (Kepler), only one result is returned for nested projects.

Anyway, here's how to use working set in open resource (the example is not of a resource in a nested module as in this case Kepler don't show duplicate results; so the example is just of two different resources baring the same name in two different modules):

(1) Hit the ctrl+shift+R keys. I searched for a resource called pom.xml. You can see two results:

open resource no working set

(2) Press the little downward-pointing arrow on the top right of the window and choose Select Working Set...:

open resource select working set

(3) Check the radio button of Selected Working Sets and check the desired projects (in your case the leaf projects):

enter image description here

(4) And voila, Open Resource returns only one result:

open resource after working set is selected

Gramps answered 22/7, 2013 at 21:21 Comment(4)
I do not want use search open as it is time consuming & it does not make sense using it to open file .. i would rather visually distinguish the path of the fileFranco
@Franco you only need to choose in the Open Resource window the Working Set once and it'll be used each time you use it for search, it's not "open search".Gramps
@Franco I hope the snapshots are right, I can't see them in stack myself (imgur is blocked here...).Gramps
I think probably working set is the only option i have tried this earlier but only issue is you have to deselect everytime.. however it is weird that eclipse shows the parent & other modules as path for the same file. I was though looking for other setting that can help show only path where in the file actually resides.Franco
P
16

You are probably talking about a kind of duplication between parent project and its sub-modules. In the latest version of Eclipse (from 3.6 maybe and sure from 3.7) there is a new option

Menu Windows >

Item Preferences >

    Tree item Maven >

       Option : Hide folders of physically nested modules

This would not work on a existing project. You must delete them (logically) and re-import them

Pneumoconiosis answered 22/7, 2013 at 21:40 Comment(7)
It is not working by checking above option.. for example if webservice.java is checked in projservice maven project & projparent is parent maven project of projservice. What I see on openning resources is /projservice/webservice.java & /projparent/projservice/webservice.java... not sure how to get rid of redudant /projparent/projservice/webservice.java entry into open resouces.. I do not want use search open as it is time consuming & it does not make sense using it to open file .. i would rather visually distinguish the path of the fileFranco
A similar option is available in Kepler (4.3) but it doesn't work for me. You can access it through the preferences: In the Maven tab, you can check off "Hide folders of physically nested modules (experimental)"Bunion
As I said, you MUST delete and re-import them activate this feature, but it could still not work ... ah ... IntelliJ Idea is quite better for that !Winifredwinikka
Works when re-importing all projects as "Existing Maven projects"Lecce
In Eclipse Mars the feature is still marked as "Experimental".Devilkin
Really ? Indeed, last time I imported a maven project into Eclipse Mars 1, then it automatically found the appropriate structure, hiding nested directories and showing the rights modules.Winifredwinikka
There's a catch: On Eclipse Oxygen, it doesn't work for me if I import the projects with 'Open project from filesystem'. But it works fine using File -> Import ... -> Maven -> Existing Maven Projects.Theodor
U
0

I just had the same issue and what worked for me was to select Filter Duplicated Resources in the Open Resource dialog:

Open menu Enable filter

Another (unrelated) useful feature is to hide submodule-folders from the parent-project in the package explorer.
This can be done by using the Maven modules filter in the menu of the package explorer:
Enable maven modules filter

Tested with Eclipse 2019-06 (4.12.0)

Uranometry answered 24/10, 2019 at 7:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.