Maven 常規錯誤一覽及解決方案

更新信息

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>





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章