【问题标题】:Eclipse-Maven: Updating project excludes src/main/resources folder from build pathEclipse-Maven:更新项目从构建路径中排除 src/main/resources 文件夹
【发布时间】:2016-10-12 13:12:14
【问题描述】:

我今天升级了我的 Spring Tool Suite,从那以后我一直坚持正确地构建项目。当我 Maven->Update Project 时,它不包括 src/main/resources 文件夹。如果我“删除”该排除项(使其成为“排除(无)”),则一切正常。但是,当我再次执行 Maven->Update Project 时,它归结为这一点。

我已经浏览了 100 个链接,但到目前为止还没有运气。更新前一切正常。

如何让 Maven 包含 src/main/resources 和 src/test/resources?

包含资源文件夹时的.classpath文件(我希望默认生成的那个):

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/classes" path="src/main/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
        <attributes>
            <attribute name="owner.project.facets" value="jst.web"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="test">
        <attributes>
            <attribute name="optional" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path=".apt_generated">
        <attributes>
            <attribute name="optional" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

.classpath 文件当我做 Maven->更新项目

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
        <attributes>
            <attribute name="owner.project.facets" value="jst.web"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="test">
        <attributes>
            <attribute name="optional" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path=".apt_generated">
        <attributes>
            <attribute name="optional" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

【问题讨论】:

  • 如果您从 Spring Tool Suite 中删除项目(不删除磁盘上的文件),然后删除所有 Eclipse 特定文件(如 .classpath)并重新将其作为 Maven 项目重新导入,会发生什么情况?这个问题非常奇怪。另外,您使用的是最新的 M2E 吗?
  • 尝试删除并重新导入几次。只要在工作区中构建/加载项目,它就会执行相同的操作。在我的 Windows 中,M2E 版本是 1.7,发生了这个问题。相同的项目在 M2E 版本为 1.5 的 Ubuntu 中运行良好。在我升级 Spring 工具套件之前,它在 Windows 中也可以正常工作:(
  • 您的pom.xml 是什么样的?这些资源是否从您的 pom.xml 配置中排除?
  • @GeminiKeith 不,我的 pom.xml 甚至不包含 标签。
  • @Tunaki *.com/questions/7754255/… 告诉我们这是正确的行为!但是,我在不同的版本中得到了不同的行为。

标签: java eclipse spring maven spring-tool-suite


【解决方案1】:

如果我看一下我的 eclipse 配置,它看起来和你的完全一样,但排除了。

【讨论】:

  • 用 .classpath 文件更新了问题