在 Eclipse Dynamic Web Project 中 Web.xml 在哪里

在 Eclipse 中,我单击 File-> New-> Dynamic Web Project 我正在学习 Jersey 的一个教程,它希望我在 web.xml 文件中修改一些内容... ... 但是我甚至找不到这个文件。 我到底做错了什么?

enter image description here

160851 次浏览

When you create a Dynamic Web Project you have the option to automatically create the web.xml file. If you don't mark that, the eclipse doesn't create it...

So, you have to add a new web.xml file in the WEB-INF folder.

To add a web.xml click on Next -> Next instead of Finish. You will find it on the final screen of the wizard.

The web.xml file should be listed right below the last line in your screenshot and resides in WebContent/WEB-INF. If it is missing you might have missed to check the "Generate web.xml deployment descriptor" option on the third page of the Dynamic web project wizard.

When you open Eclipse you should click FileNewDynamic Web Project, and make sure you checked Generate web.xml, as described above.

If you have already created the project, you should go to the WebContent/WEB-INF folder, open web.xml, and put the following lines:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Application Name </display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

If you missed to check the "generate web.xml" option when creating a new project, no worries If it is a Dynamic Web Project in your project right click on "Deployment Descriptor:...." and Click on "Generate Deployment Descriptor Stub" this will create a minimal /webapp/WEB-INF/web.xml.

you can do it by Dynamic Web Project –> RightClick –> Java EE Tools –> Generate Deployment Descriptor Stub.

Might be your project is not JEE nature, to do this Right Click -> Properties -> Project Facets and click Convert to facet and check dynamic web module and ok. Now you will be able to see Java EE Tools.

If you don't see the web.xml file in WEB-INF folder,

enter image description here

- Select Deployment Descriptor and right click on it.
- Then select the Generate Deployment Descriptor Stub

enter image description here

Finally you get web.xml file.

enter image description here

Follow below steps to generate web.xml in Eclipse with existing Dynamic Web Project

  1. Right Click on Created Dynamic Web Project
  2. Mouse Over Java EE Tools
  3. Click on Generate Deployment Descriptor Stub
  4. Now you are able to see web.xml file on WEB-INF folder

enter image description here

For gradle / maven project you can use src/main/webapp/WEB-INF folder by default:

- main
- - java
- - resources
- - webapp
- - - META-INF
- - - - context.xml
- - - WEB-INF
- - - - web.xml

I think you are creating a project in the wrong way,I am going to post here in step by step

Step 1: File>>New>>Project>>Web>>Dynamic Web Project

Step 2: Enter Project Name>>Next>>Next>>

Step 3: Check the checkbox for Generate web.xml deployment descriptor

Step 4: Finish

Please follow this way you will get you web.xml file under WEB-INF folder

If your deployment descriptor tab is disabled, then click on update libraries it will also do your work. It will create. Xml file in Web content

You can try this: right-click on the project and select Java EE Tools -> Generate Deployment Descriptor Stub. web.xml should be generated.