更新信息

2016-03-13 开贴


想法很单纯,将自己在Maven学习过程中遇到的各种麻烦列出来,并提供解决方案待查。

正题开始,遇到错误可通过报错信息对号入座:


错误提示:web.xml is missing and <failOnMissingWebXml> is set to true

推测原因:这是maven自身的错误。意思是你的web应用项目中缺少web.xml文件,但是如今web.xml在众多的web应用项目中已成为可有可无的存在。但maven还是将此视为必须。

解决方案:加入以下代码到你的pom.xml文件中,不需要创建那个无用的web.xml

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.6</version>
      <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
      </configuration>
    </plugin>
  </plugins>
</build>


错误提示:Dynamic Web Module 3.0 requires Java 1.6 or newer

推测原因:无非是项目中Project Facets的Dynamic Web Module和Java版本对应不一致造成。调整Dynamic Web Module的版本时,底部会有相应提示。

解决方案:根据调整Java版本号即可,也可以修改pom.xml,告诉Maven编译时需要的Java版本

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.3.2</version>
      <configuration>
        <source>1.6</source>
        <target>1.6</target>
      </configuration>
    </plugin>
  </plugins>
</build>


错误提示:Plugin execution not covered by lifecycle configuration

推测原因:eclipse的m2e插件还没有支持到execution

参考:https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html

解决方案:在<plugins>标签添加上级标签<pluginsManagement>

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.2</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</pluginManagement>