pom.xml中web.xml is missing and is set to true錯誤的解決

問題描述:有時候新建的maven工程後,項目的pom.xml中報錯:web.xml is missing and <failOnMissingWebXml> is set to trueweb

如圖:apache

        

解決分兩種狀況(三種解決方法):app

1.若項目中不須要web.xml文件,且不是Web工程,則直接在pom.xml文件中加入如下配置,而後update一下項目:webapp

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

 

 

2.項目是Web工程,則須要web.xml文件(兩種解決方案)maven

  1)最簡單最直接的是在src/main/webapp/下新建WEB-INF/web.xml(也能夠從其餘項目中拷貝一個web.xml過來),以下圖。而後刷新項目:ui

            

  2)最可靠的是讓項目自動 WEB-INF/web.xml生成。操做步驟以下:spa

    ①右擊項目,而後點擊Properties-->Project Facets,將在右側Dynamic Web Module選中項去除,再點擊Apply(應用)。code

           

    

    ②而後從新勾選Dynamic Web Module,點擊下方的Further configuration available... 在彈出的窗口中配置Content directory的值填入:src/main/webapp,點擊ok ,再點擊Appy --> Apply and Close.刷新工程便可。以下圖:xml

           

    

    ③完成後,自動生成的結構以下圖,很是完整:blog

           

 

  若過程當中還有其餘問題,歡迎留言一塊兒解決。

相關文章
相關標籤/搜索