web.xml文件報錯

轉載自:http://blog.csdn.net/sinat_22911279/article/details/77454139

提示信息應該能看懂。也就是缺少了web.xml文件,被設置成true了。
搜索了一下,Stack Overflow上的答案解決了問題,分享一下。
目前被頂次數最多的回答原文如下:
This is a maven error. It says that it is expecting a web.xml file in your project because it is a web application, as indicated by war. However, for recent web applications a web.xml file is totally optional. Maven needs to catch up to this convention. Add this to your maven pom.xml to let maven catch up and you don’t need to add a useless web.xml to your project:
大意是說這是一個Maven錯誤,在最近的web應用開發中web.xml文件已經變得可有可無了。不過Maven還沒有跟上這一變化,我們只要在pom.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>

“告知”maven即可。這樣做的好處是我們不必在項目生中成一個無用的web.xml文件。在更新版本(具體從哪一個版本開始我也不知道~~)的maven中已經不存在web.xml文件缺失的問題,我們只需要處理被設置成tue的問題即可。也就是在pom.xml中添加如下配置即可。

<properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>

其他方案:(生成web.xml——>部署運行時文件路徑)
you can do it also like this:

Right click on Deployment Descriptor in Project Explorer.
Select Generate Deployment Descriptor Stub.
It will generate WEB-INF folder in src/main/webapp and an web.xml in it.

這是被採納方案,也就是說在項目瀏覽器中右鍵單擊Deloyment Descriptor,選擇生成部署描述符存根:Generate Deployment Descriptor Stub。

操作後會在項目的src/main/webapp/WEB-INF目錄下生成web.xml文件。我按照這個方法生成了web.xml文件,但是仍然報錯。如果你也是的話可以接着往下看。
Here are the steps you can follow:

You can check this by right clicking your project, and open its Properties dialogue, and then “Deployment Assembly”, where you can add Folder /src/main/webapp. Save the setting, and then,
Go to Eclipse menu Project -> Clean… and clean the project, and the error should go away.
此時需要對src/main/webapp文件進行運行時的路徑部署,以保證服務器正常運行。
也就是說需要部署一下src/main/webapp(剛生成的web.xml就在該文件夾下)文件夾,Deployment的作用是會在運行時將相應的resource複製到web服務器的相應目錄下(通過Deploy Path指定),保證web應用正常運行。
經過這兩步,問題解決。

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