我将 Maven 2.0.9 与 Eclipse 3.3.2 一起使用。
我习惯于每天由mvn clean install
. 然后,如果我刷新我的 Eclipse 项目,它将被 Maven目标目录中的文件“污染”。
这在执行搜索、通过“开放资源”获取资源等时非常烦人。
有没有办法避免 Eclipse 在这个文件夹中查找?
右键单击要忽略的文件夹,打开“属性”对话框,选择“资源”选项卡并选中“派生”框
在 Maven 中重新配置“clean”以不删除目标目录:
<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>
(位于:http ://maven.40175.n5.nabble.com/how-to-NOT-delete-target-dir-td3389739.html#a3413930 )
Indigo 解决方案 [SR2]
Project Explorer
> Customize View
> Filters
>[*] Maven Build Folder
我对这个问题非常生气,所以我写了一个插件来解决它。您可以从以下位置获取源代码和 jar:
为了解决这个问题,这是我所做的:
------------在此处剪切脚本----------------
/*
* 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);
}
}
}
}
首选项 > 团队 > 忽略的资源
添加“目标”,然后重新启动 Eclipse。
您是否尝试配置“Java 元素过滤器”选项对话框(通过项目资源管理器的右上角箭头)?
如果需要,您可以定义自己的ViewerFilter
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 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 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.
maven 插件不会隐藏目标目录。但是,它确实使用 maven 目标文件夹来配置 eclipse。所以eclipse使用target/classes和target/test-classes,eclipse过滤掉这些文件夹。这是由“mvn eclipse:eclipse”以及 m2eclipse 插件完成的。除了这两个文件夹(例如生成的 jar 文件)之外,剩下的就是目标目录中的所有内容。
您可以为包资源管理器创建一个过滤器,但这不会影响“开放资源”。
如果您经常使用“mvn clean install”,使用资源过滤器看起来可以解决问题。
基本上,它会将“目标”添加到子文件夹中,以将文件夹直接排除到 .project 文件中。运行此脚本后,如果将项目导入 Eclipse,您可以看到设置“项目”->“属性”->“资源”->“资源过滤器”。在此之前,每当我运行 mvn clean install 时,eclipse 占用了我 50% 的 CPU,但现在它在构建项目时保持在 5% 以下。
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>/' {} \;
}
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.