Eclipse中创建Maven风格目录,如何隐藏Package Explorer中的src根目录
src Directory in Eclipse for Maven-Style Projects Hey there! I totally get it—having that extra root src directory cluttering up your Package Explorer when you’ve set up your Maven-style src/main and src/test folders is super annoying. Here are a few solid ways to hide it cleanly:
Method 1: Filter the Root src Folder Directly
This is the quickest fix if you just want to hide that one folder without changing your project structure:
- Open the Package Explorer, then click the tiny dropdown arrow (View Menu) in the top-right corner of the panel.
- Select Filters... from the menu.
- In the Filters window, switch to the Resource tab.
- Click the Add... button, navigate to your project’s root
srcfolder, select it, and hit OK. - Back in the Filters window, check the box next to the
srcfolder you just added, then click OK. The folder will disappear from your Package Explorer immediately.
Method 2: Convert to a Maven Project (Recommended)
If you haven’t already, turning your project into a proper Maven project will not only hide the root src but also automate a lot of build path and directory management:
- Right-click your project in Package Explorer > Configure > Convert to Maven Project.
- Fill in the required fields (Group Id, Artifact Id, Version) in the popup, then click Finish.
- Once converted, Eclipse will automatically recognize the Maven directory structure. Switch your Package Explorer to Hierarchical presentation (View Menu > Presentation > Hierarchical) to see the clean
src/main/javaandsrc/test/javafolders nested under a collapsedsrcentry (or it might not show the rootsrcat all, depending on your view settings). - Pro tip: Use the Maven Projects view (Window > Show View > Other... > Maven > Maven Projects) for an even cleaner view of your project’s Maven-specific directories.
Method 3: Use Working Sets to Curate What You See
If you want more control over which folders are displayed, Working Sets are a great option:
- Click the View Menu in Package Explorer > Working Sets > Edit Working Sets....
- Click New, choose either Java or Resource as the working set type, give it a name (like "Project Sources"), and click Next.
- Select only the folders you want to see (
src/main/java,src/test/java, maybesrc/main/resources) and click Finish. - Back in Package Explorer, click View Menu > Top Level Elements > Working Sets. Now only the folders in your Working Set will be visible, and the root
srcwill be hidden entirely.
Quick Note
If you ever need to bring the root src back, just reverse the steps: for Method 1, uncheck the folder in Filters; for Method 3, switch back to Projects as the top-level element.
内容的提问来源于stack exchange,提问作者nappyfalcon

