Maven 战争在两个地方有 META-INF 文件夹 [英] Maven war has META-INF folder in two places
问题描述
我正在开发一个使用 JAAS 的项目,不幸的是,Tomcat 需要将一个文件放在战争根目录的 META-INF 文件夹中
I'm working on a project which uses JAAS and unfortunately for me Tomcat requires a file to be put in a META-INF folder in the root of the war
app.war
|__META-INF
| |___context.xml
...
我认为这已经很奇怪了,因为 WAR 的默认 META-INF 位置位于类文件夹中.
I think that it's already weird since the default META-INF location for WAR's is in the classes folders.
app.war
|__WEB-INF
| |__classes
| |__META-INF
...
所以我使用的是 Maven,它指出 src/main/resources/META-INF 中的任何内容都将被复制到适当的位置,它确实如此.奇怪的是,它还在文件结构的根目录中创建了一个 META-INF 文件夹,给我留下了 2 个 META-INF 文件夹.
So I'm using Maven, which states that anything in src/main/resources/META-INF will be copied to the appropriate place, which it does. The weird thing is that it is also creating a META-INF folder in the root of the file structure leaving me with 2 META-INF folders.
项目结构
app
|__src/main/java
|__src/main/resources
| |__META-INF
| |__context.xml
...
mvn打包后
app
|__META-INF [1]
|__WEB-INF
| |__classes
| |__META-INF [2]
| |__context.xml
...
所以,如果战争标准规定 META-INF 应该在 classes 文件夹下,如 #2,那么为什么 maven war 会创建 #1 文件夹.有没有办法让它将文件复制到该文件夹而不是#2?
So, if the war standard states that META-INF should be under classes folder, as in #2, why maven war creates the #1 folder. And is there a way to make it copy files into that folder instead of #2?
问候
推荐答案
于是我找到了这个:
这表明拥有 2 个 META-INF 文件夹不是问题.挖掘了一下我发现:
which states that having 2 META-INF folders is not a problem. Digging a little I found:
其中说明了 META-INF 文件夹:
which states about the META-INF folder:
JAR 文件本质上是一个包含可选 META-INF 目录的 zip 文件....META-INF 目录(如果存在)用于存储包和扩展配置数据,包括安全性、版本控制、扩展和服务.
A JAR file is essentially a zip file that contains an optional META-INF directory. ...The META-INF directory, if it exists, is used to store package and extension configuration data, including security, versioning, extension and services.
还有这个:
在第 10.6 节中,说明了 WAR 文件结构:
which, on section 10.6, states about the WAR file structure:
当打包成这样的形式时,会出现一个 META-INF 目录包含对 Java 归档工具有用的信息.此目录不能直接容器作为内容来响应 Web 客户端的请求,尽管它的servlet 代码可以通过 getResource 和 getResourceAsStream 看到内容调用 ServletContext. 此外,任何访问 META-INF 中资源的请求必须使用 SC_NOT_FOUND(404) 响应返回目录.
When packaged into such a form, a META-INF directory will be present which contains information useful to Java archive tools. This directory must not be directly served as content by the container in response to a Web client’s request, though its contents are visible to servlet code via the getResource and getResourceAsStream calls on the ServletContext. Also, any requests to access the resources in META-INF directory must be returned with a SC_NOT_FOUND(404) response.
所以根据 WAR 规范,正确的位置是 WEB-INF/classes/META-INF.然而,由于 war 是一个特殊的 jar 文件,因此将/META-INF 作为扩展点是有意义的.我们可以在 JPA persistence.xml 和 Tomcat context.xml 文件中看到如此不同的用途:前者应该放在 WEB-INF/classes/META-INF 中,而后者应该放在/META-INF 中.
So from the WAR spec the right place is WEB-INF/classes/META-INF. Yet, since war is a special jar file, it makes sense to have /META-INF as a point for extensions. One can see such different uses in JPA persistence.xml vs. Tomcat context.xml files: the former should be placed in WEB-INF/classes/META-INF while the latter in /META-INF.
这篇关于Maven 战争在两个地方有 META-INF 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!