cvc-complex-type.2.4.d:从元素'testResources'开始发现无效内容。此时不会有子元素

时间:2014-02-05 08:57:32

标签: xml eclipse maven

我尝试从eclipse中的旧项目执行maven构建文件 使用eclipse:

Version: Kepler Service Release 1
Build id: 20130919-0819

我有这个不断出错的maven代码:

<build>
  <pluginManagement>
    <plugins>
      <!-- Use version 2.3 of the resources plugin 
       to pickup a needed filtering bugfix -->
      <plugin>                
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.3</version>
      </plugin>
    </plugins>

    <!-- Enable filtering of the properties files -->
    <testResources>
      <testResource>
            <directory>src/test/properties</directory>
            <filtering>true</filtering>
      </testResource>
    </testResources>
    </pluginManagement>
  </build>

标签:标记为红色,错误显示:

cvc-complex-type.2.4.d: Invalid content was found starting   with element 'testResources'. No child element is expected at   this point

这是使用-X compile运行时的错误堆栈:

[ERROR]   
[ERROR]   The project com.projectdarkstar.example.projectsnowman:snowman-server:0.2-SNAPSHOT (D:\dev\java\servers\snowman\snowman-server\pom.xml) has 1 error
[ERROR]     Malformed POM D:\dev\java\servers\snowman\snowman-server\pom.xml: Unrecognised tag: 'testResources' (position: START_TAG seen ... Enable filtering of the properties files -->\r\n    <testResources>... @173:20)  @ D:\dev\java\servers\snowman\snowman-server\pom.xml, line 173, column 20 -> [Help 2]
org.apache.maven.model.io.ModelParseException: Unrecognised tag: 'testResources' (position: START_TAG seen ... Enable filtering of the properties files -->\r\n    <testResources>... @173:20) 
    at org.apache.maven.model.io.DefaultModelReader.read(DefaultModelReader.java:127)
    at org.apache.maven.model.io.DefaultModelReader.read(DefaultModelReader.java:91)
    at org.apache.maven.model.building.DefaultModelProcessor.read(DefaultModelProcessor.java:77)
    at org.apache.maven.model.building.DefaultModelBuilder.readModel(DefaultModelBuilder.java:456)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:261)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:232)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:410)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:379)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:495)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:379)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:343)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:636)
    at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:585)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:234)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.codehaus.plexus.util.xml.pull.XmlPullParserException: Unrecognised tag: 'testResources' (position: START_TAG seen ... Enable filtering of the properties files -->\r\n    <testResources>... @173:20) 
    at org.apache.maven.model.io.xpp3.MavenXpp3ReaderEx.checkUnknownElement(MavenXpp3ReaderEx.java:157)
    at org.apache.maven.model.io.xpp3.MavenXpp3ReaderEx.parsePluginManagement(MavenXpp3ReaderEx.java:3615)
    at org.apache.maven.model.io.xpp3.MavenXpp3ReaderEx.parseBuild(MavenXpp3ReaderEx.java:1220)
    at org.apache.maven.model.io.xpp3.MavenXpp3ReaderEx.parseModel(MavenXpp3ReaderEx.java:2755)
    at org.apache.maven.model.io.xpp3.MavenXpp3ReaderEx.read(MavenXpp3ReaderEx.java:4631)
    at org.apache.maven.model.io.xpp3.MavenXpp3ReaderEx.read(MavenXpp3ReaderEx.java:4590)
    at org.apache.maven.model.io.DefaultModelReader.read(DefaultModelReader.java:118)
    ... 25 more

1 个答案:

答案 0 :(得分:3)

<testResources> should not be inside <pluginManagement>

查看maven reference

所以你应该使用

<build>
  <pluginManagement>
    <plugins>
      <!-- Use version 2.3 of the resources plugin 
       to pickup a needed filtering bugfix -->
      <plugin>                
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.3</version>
      </plugin>
    </plugins>
  </pluginManagement>
  <!-- Enable filtering of the properties files -->
  <testResources>
    <testResource>
          <directory>src/test/properties</directory>
          <filtering>true</filtering>
    </testResource>
  </testResources>
</build>