Is there a way to hide Maven 2 "target/" folder in Eclipse 3?
I'm using maven 2.0.9 with Eclipse 3.3.2.
I'm used to launching a fresh build once per day by a mvn clean install
.
Then, if I refresh my Eclipse project, it will be "polluted" by files from Maven's target directory.
That's very annoying while performing searches, getting resources by "open resource" and so on.
Is there a way to avoid Eclipse looking in this folder?
Asked by: Melissa228 | Posted: 28-01-2022
Answer 1
Right click on the folder you want to ignore, open the "Properties" dialog, chose the "Resource" tab and check the box that says "Derived"
Answered by: Lucas466 | Posted: 01-03-2022Answer 2
Reconfigure "clean" in Maven not to delete target directory:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<!-- delete directories that will be generated when you
start the develpment server/client in eclipse
-->
<fileset>
<directory>target</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
(found at: http://maven.40175.n5.nabble.com/how-to-NOT-delete-target-dir-td3389739.html#a3413930)
Answered by: Ted307 | Posted: 01-03-2022Answer 3
Solution for Indigo [SR2]
Project Explorer
> Customize View
> Filters
> [*] Maven Build Folder
Answer 4
I have been so pissed by this problem that I wrote a plugin to solve it. You get get the source and jar from:
https://github.com/YA2O/Eclipse_Plugin_Target_Derivator
Answered by: Vivian400 | Posted: 01-03-2022Answer 5
To solve this problem here is what I did:
-----------Cut below here for script--------------
/*
* Menu: Find System Prints > Beanshell
* Script-Path: /GroovyMonkeyScripts/monkey/UpdateMavenDerived_Beanshell.gm
* Kudos: Bjorn Freeman-Benson & Ward Cunningham & James E. Ervin
* License: EPL 1.0
* LANG: Beanshell
* DOM: http://groovy-monkey.sourceforge.net/update/plugins/net.sf.groovyMonkey.dom
*/
out.println("Setting target directories to derived status.");
var projects = workspace.getRoot().getProjects();
for ( var i = 0; i < projects.length; i++) {
var project = projects[i];
if (project.isOpen()) {
out.println("Project: " + project.getName());
var members = project.members();
for ( var j = 0; j < members.length; j++) {
if (members[j].getName().equals("target")) {
out.println("setting derived status on: "+ members[j].getFullPath());
members[j].setDerived(true);
}
}
}
}
Answered by: Eric615 | Posted: 01-03-2022
Answer 6
Did you try configuring the "Java Element Filters" option dialog box, (through the top-right arrow of the project explorer) ?
If needed, you can define your own ViewerFilter
Answered by: Dexter448 | Posted: 01-03-2022Answer 7
Preferences > Team > Ignored Resources
Add "target", and restart Eclipse.
Answered by: Gianna857 | Posted: 01-03-2022Answer 8
The maven plugin does not hide away the target directory. It does however use the maven target folders to configure eclipse. So target/classes and target/test-classes are used by eclipse, and eclipse filters these folders out. This is done by "mvn eclipse:eclipse" as well as by the m2eclipse plugin. What is left visible is everything in the target directory besides these two folders (the generated jar file for example).
You can create a filter for the package explorer, but that will not influence the "open resource".
Answered by: Thomas478 | Posted: 01-03-2022Answer 9
I had some issues because some solutions here only work for some views, so I made an illustrated summary.
Tested in Eclipse 4.4 (Luna), should work like this since 3.7 according to other answers here.
Package Explorer
Package Explorer View Menu → Filters...
→ check Name filter patterns
and input target
.
Be careful, this will hide all folders and files named target
, not just the default maven build directory! The Project Explorer view has a better option without this issue.
Project Explorer
Project Explorer View Menu → Custom View...
→ search for "maven" and check Maven build folder
.
Checking this option hides the build directory as defined in the projects pom.xml configuration.
Answer 10
Are you using the Maven plugin for Eclipse?
I would imagine it would hide some of the 'pollution' for you.
It would also allow you to perform the build within Eclipse - meaning it would refresh the project view for you at the same time.
Answered by: Blake329 | Posted: 01-03-2022Answer 11
Using Resource filter looks solve issue if you using 'mvn clean install' frequently.
Basically it will add 'target' to and sub folders to exclude folder directly to .project file. After run this script, if you import project to eclipse, you can see the setting 'Project'->'Properties'->'Resource'->'Resource Filters'. Before this whenever I run mvn clean install, eclipse took 50% of my CPU but now it stay under 5% while build project.
function eclipse-setup() {
mvn eclipse:clean
mvn eclipse:eclipse
#maven target folders
find . -name .project -exec sed -i.MSORG 's/<\/projectDescription>/<filteredResources> <filter> <id>1314376338264<\/id> <name><\/name> <type>26
<\/type> <matcher> <id>org.eclipse.ui.ide.multiFilter<\/id> <arguments>1.0-name-matches-false-false-target<\/arguments> <\/matcher> <\/filter> <filt
er> <id>1314387234341<\/id> <name><\/name> <type>6<\/type> <matcher> <id>org.eclipse.ui.ide.multiFilter<\/id> <arguments>1.0-name-matches-false-fals
e-*.cache.html<\/arguments> <\/matcher> <\/filter> <\/filteredResources><\/projectDescription>/' {} \;
}
Answered by: Lucas287 | Posted: 01-03-2022
Answer 12
When Eclipse freezes, looking at the process activity, I can see it browsing all my target, .hg and .git directories. Moreover, those directories are also copied into Eclipse's bin directory. A lot of CPU and disk usage for nothing.
Not cleaning the target directory is not an acceptable solution.
There was a solution using a Monkey script (http://maven.40175.n5.nabble.com/Eclipse-amp-target-directory-td72354.html) but the project has been closed.
I still look for a solution to tell Eclipse to ignore Maven target directories, as well as .hg and .git directories.
Eclipse continuously watching those is a pain.
I also use m2eclipse but it doesn't solve that issue.
Answered by: Ryan533 | Posted: 01-03-2022Similar questions
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)