49

我将 Maven 2.0.9 与 Eclipse 3.3.2 一起使用。

我习惯于每天由mvn clean install. 然后,如果我刷新我的 Eclipse 项目,它将被 Maven目标目录中的文件“污染”。

这在执行搜索、通过“开放资源”获取资源等时非常烦人。

有没有办法避免 Eclipse 在这个文件夹中查找?

4

12 回答 12

58

右键单击要忽略的文件夹,打开“属性”对话框,选择“资源”选项卡并选中“派生”框

于 2008-11-13T01:20:45.160 回答
25

在 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 )

于 2011-04-04T13:35:13.683 回答
18

Indigo 解决方案 [SR2]

Project Explorer> Customize View> Filters>[*] Maven Build Folder

于 2013-04-26T16:32:40.393 回答
10

我对这个问题非常生气,所以我写了一个插件来解决它。您可以从以下位置获取源代码和 jar:

https://github.com/YA2O/Eclipse_Plugin_Target_Derivator

于 2012-01-23T13:35:25.970 回答
4

为了解决这个问题,这是我所做的:

  • 为 Eclipse 安装 Groovy Monkey
  • 创建了一个 Bean Shell 脚本“UpdateMavenDerived_Beanshell.gm”以将任何名为 target 的目录标记为派生的。
  • ------------在此处剪切脚本----------------

    /*
     * 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);
                }
            }
        }
    }
    
    于 2011-06-15T15:12:44.883 回答
    3

    首选项 > 团队 > 忽略的资源

    添加“目标”,然后重新启动 Eclipse。

    于 2009-05-01T15:42:42.937 回答
    3

    您是否尝试配置“Java 元素过滤器”选项对话框(通过项目资源管理器的右上角箭头)?

    如果需要,您可以定义自己的ViewerFilter

    于 2008-11-12T12:25:14.117 回答
    2

    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 MenuFilters... → 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.

    Package Explorer Menu Package Explorer Dialog

    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.

    Project Explorer Menu Project Explorer Dialog

    于 2015-03-26T03:19:13.873 回答
    2

    maven 插件不会隐藏目标目录。但是,它确实使用 maven 目标文件夹来配置 eclipse。所以eclipse使用target/classes和target/test-classes,eclipse过滤掉这些文件夹。这是由“mvn eclipse:eclipse”以及 m2eclipse 插件完成的。除了这两个文件夹(例如生成的 jar 文件)之外,剩下的就是目标目录中的所有内容。

    您可以为包资源管理器创建一个过滤器,但这不会影响“开放资源”。

    于 2008-11-12T12:20:26.920 回答
    1

    你在为 Eclipse 使用 Maven 插件吗?

    我想它会为你隐藏一些“污染”。

    它还允许您在 Eclipse 中执行构建——这意味着它会同时为您刷新项目视图。

    Maven 2 日食

    于 2008-11-12T11:23:49.857 回答
    1

    如果您经常使用“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>/' {} \;
    
    }
    
    于 2011-08-26T20:06:52.403 回答
    0

    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.

    于 2011-05-11T13:34:33.257 回答