gpt4 book ai didi

jakarta-ee - 使用/META-INF/resources时,WEB-INF去哪儿了?

转载 作者:行者123 更新时间:2023-12-03 16:52:01 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Splitting up shared code and web.xml from WAR project to common JAR project

(3 个回答)


3年前关闭。




我将我所有的网络资源放入 /META-INF/resources ,所以我可以在不同的网络应用程序中重用它们。

但是 web.xml 呢?内部 WEB-INF/ ?我是否必须将其保留在 src/main/webapp/ 中?或者我可以把它放在src/main/resources/下面吗?还有?

如果是这样,我必须把它放在哪里? src/main/resources/WEB-INF/src/main/resources//META-INF/resources/WEB-INF/ ?

我使用 Maven 和 Assembly 插件来构建我的项目,而不是 WAR 插件。

最佳答案

简而言之,你可以。

自 Servlet 3.0 起,您可以在常规 jar 文件中的 Web 应用程序之间共享 Java 类、Web 资源和 web-fragment.xml 文件。这些 jars 被称为“网络片段”。

来自 Servlet 3.1 规范的 §8.2.1:

...

A web fragment is a logical partitioning of the web application in such a way that the frameworks being used within the web application can define all the artifacts without asking developers to edit or add information in the web.xml. It can include almost all the same elements that the web.xml descriptor uses. However the top level element for the descriptor MUST be web-fragment and the corresponding descriptor file MUST be called web-fragment.xml. The ordering related elements also differ between the web-fragment.xml and web.xml See the corresponding schema for web-fragments in the deployment descriptor section in Chapter 14.

If a framework is packaged as a jar file and has metadata information in the form of deployment descriptor then the web-fragment.xml descriptor must be in the META-INF/ directory of the jar file.

...



因此,与其尝试以某种方式嵌入 web.xml 文件,您只需要将相同的内容放在 META-INF/web-fragment.xml 文件中(它共享大部分 web.xml XSD)。

正如您已经发现的那样,您的网络资源位于 META-INF/resources 中。

总之,您可以轻松地在普通 jar 文件中构建共享组件。你真的不需要搞乱 maven-assembly-plugin 来完成这个。

关于jakarta-ee - 使用/META-INF/resources时,WEB-INF去哪儿了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51613171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com