Can I have two web.xml files in a single web application?

后端 未结 2 1737
無奈伤痛
無奈伤痛 2021-01-19 03:07

Can i Have a single application with more than one web.xml files? And can two applications have a parent child relationship so that there are two web.xml?

相关标签:
2条回答
  • 2021-01-19 03:56

    For below servlet 3.0 you cannot.

    If you are using 3.0 there is a possibility.

    In JSR 315: Java Servlet 3.0 Specification, web-fragment.xml is introduced for pluggability of library jars which are packaged under WEB-INF/lib. The content of web.xml and web-fragment.xml are almost the same. One can define servlets, filters and listeners there. One can also specify metadata-complete=true in a given web-fragment.xml. In the latter case, the annotation processing of classes in that jar would be skipped. With web-fragment.xml, library jars can be self-contained and provide web related metadata information.

    For sure, having two xml creates confusion and besides all, If you explain whats your exact requirement, you'l get a good/standard solution for your problem.

    0 讨论(0)
  • 2021-01-19 04:00

    Can i Have a single application with more than one web.xml files?

    It depends on the approach.

    Approach 1

    If you are working in an environment where there are certain servlets (I remember I worked on an old project where there was a Minification servlet and its purpose was to minify the JS/CSS at deploy time) and settings like e.g certain user-contraints and realms that you don't want configured on your development environment since you will be working with exploded JS/CSS and you want to bypass basic secuirty constraints configured in the application just for ease of development but you want them all tested out on QA , so it "sort of" of makes sense to have 2 different deployment descriptors configured for the same application. One in which you have only the basic settings to just deploy the application for development and on the other you have all your production settings that you want tested out on QA from A to Z.

    But again, I want to make it clear that you can deploy you application using only ONE deployment descriptor.

    Approach 2

    Lets say you want your deployment descriptor to be broken down into small parts for plugg-ability purpose like you define your Servlets in one file and you define your securutiy constraints in other file. These files or web-fragments.xml can only work with Servlet3.0. If you look closely to how these fragments are used, at deploy time all these fragments are merged and read by the container as a "single" file (the deployment descriptor).

    So in the end , we again wind up with a SINGLE deployment descriptor for the application.

    0 讨论(0)
提交回复
热议问题