Java 有没有办法在 Eclipse 3 中隐藏 Maven 2“目标/”文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/283489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 12:28:44  来源:igfitidea点击:

Is there a way to hide Maven 2 "target/" folder in Eclipse 3?

javaeclipsemaven-2

提问by paulgreg

I'm using maven 2.0.9 with Eclipse 3.3.2.

我在 Eclipse 3.3.2 中使用 maven 2.0.9。

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 targetdirectory.

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

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?

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

回答by James Camfield

Are you using the Maven plugin for Eclipse?

你在使用 Eclipse 的 Maven 插件吗?

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.

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

Maven 2 Eclipse

Maven 2 日食

回答by Tobias Schulte

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

maven 插件不会隐藏目标目录。然而,它确实使用 maven 目标文件夹来配置 eclipse。所以目标/类和目标/测试类被eclipse使用,eclipse过滤掉了这些文件夹。这是由“mvn eclipse:eclipse”以及m2eclipse插件完成的。除了这两个文件夹(例如生成的 jar 文件)之外,目标目录中的所有内容都是可见的。

You can create a filter for the package explorer, but that will not influence the "open resource".

您可以为包浏览器创建过滤器,但这不会影响“打开资源”。

回答by VonC

Did you try configuring the "Java Element Filters" option dialog box, (through the top-right arrow of the project explorer) ?

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

If needed, you can define your own ViewerFilter

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

回答by VonC

Right click on the folder you want to ignore, open the "Properties" dialog, chose the "Resource" tab and check the box that says "Derived"

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

回答by VonC

Preferences > Team > Ignored Resources

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

Add "target", and restart Eclipse.

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

回答by Marx

Reconfigure "clean" in Maven not to delete target directory:

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

(found at: http://maven.40175.n5.nabble.com/how-to-NOT-delete-target-dir-td3389739.html#a3413930)

(见:http: //maven.40175.n5.nabble.com/how-to-NOT-delete-target-dir-td3389739.html#a3413930

回答by Julien Carsique

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.

当 Eclipse 冻结时,查看进程活动,我可以看到它正在浏览我的所有目标、.hg 和 .git 目录。此外,这些目录也被复制到 Eclipse 的 bin 目录中。大量的 CPU 和磁盘使用量一文不值。

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.

有一个使用 Monkey 脚本(http://maven.40175.n5.nabble.com/Eclipse-amp-target-directory-td72354.html)的解决方案,但该项目已关闭。

I still look for a solution to tell Eclipse to ignore Maven target directories, as well as .hg and .git directories.

我仍在寻找一种解决方案来告诉 Eclipse 忽略 Maven 目标目录以及 .hg 和 .git 目录。

Eclipse continuously watching those is a pain.

Eclipse 不断地看着那些是一种痛苦。

I also use m2eclipse but it doesn't solve that issue.

我也使用 m2eclipse 但它没有解决这个问题。

回答by Stephen Hart

To solve this problem here is what I did:

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

  • Install Groovy Monkey for Eclipse
  • 为 Eclipse 安装 Groovy Monkey
  • Created a Bean Shell Script "UpdateMavenDerived_Beanshell.gm" to mark any directory named target as derived.
  • 创建了一个 Bean Shell 脚本“UpdateMavenDerived_Beanshell.gm”以将任何名为 target 的目录标记为派生的。
  • -----------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);
                }
            }
        }
    }
    

    回答by Who Mobile

    Using Resource filter looks solve issue if you using 'mvn clean install' frequently.

    如果您经常使用“mvn clean install”,使用资源过滤器看起来可以解决问题。

    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.

    基本上它会将“目标”添加到子文件夹以将文件夹直接排除到 .project 文件中。运行这个脚本后,如果你将项目导入eclipse,你可以看到设置'Project'->'Properties'->'Resource'->'Resource Filters'。在此之前,每当我运行 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>/' {} \;
    
    }
    

    回答by YA2O

    I have been so pissed by this problem that I wrote a plugin to solve it. You get get the source and jar from:

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

    https://github.com/YA2O/Eclipse_Plugin_Target_Derivator

    https://github.com/YA2O/Eclipse_Plugin_Target_Derivator