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

前端 未结 12 972
[愿得一人]
[愿得一人] 2021-01-30 04:58

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,

相关标签:
12条回答
  • 2021-01-30 05:49

    To solve this problem here is what I did:

  • Install Groovy Monkey for Eclipse
  • Created a Bean Shell Script "UpdateMavenDerived_Beanshell.gm" to mark any directory named target as derived.
  • -----------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);
                }
            }
        }
    }
    
0 讨论(0)
  • 2021-01-30 05:49

    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

    0 讨论(0)
  • 2021-01-30 05:54

    Solution for Indigo [SR2]

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

    0 讨论(0)
  • 2021-01-30 05:55

    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

    0 讨论(0)
  • 2021-01-30 05:56

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

    0 讨论(0)
  • 2021-01-30 05:57

    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)

    0 讨论(0)
  • 提交回复
    热议问题