Maven战争在两个地方都有META-INF文件夹 [英] Maven war has META-INF folder in two places
问题描述
我正在一个使用JAAS的项目中,不幸的是,Tomcat要求将文件放在战争根源的META-INF文件夹中
app.war
|__META-INF
| |___context.xml
...
我认为这已经很奇怪了,因为WAR的默认META-INF位置在classes文件夹中.
app.war
|__WEB-INF
| |__classes
| |__META-INF
...
所以我正在使用Maven,它指出src/main/resources/META-INF中的所有内容都将被复制到适当的位置.奇怪的是,它还在文件结构的根目录中创建了一个META-INF文件夹,只剩下2个META-INF文件夹.
项目结构
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?
致谢
所以我发现了这一点:
指出拥有2个META-INF文件夹不是问题.挖了一点我发现:
JAR文件规范 >
说明META-INF文件夹:
JAR文件本质上是一个zip文件,其中包含一个可选的META-INF目录. ...如果有META-INF目录,它用于存储软件包和扩展程序配置数据,包括安全性,版本控制,扩展程序和服务.
和这个:
在10.6节中说明了WAR文件的结构:
打包成这种格式后,将显示一个META-INF目录,该目录 包含对Java存档工具有用的信息. 此目录不能直接 容器作为响应Web客户端请求的内容充当内容,尽管 内容通过getResource和getResourceAsStream对Servlet代码可见 .此外,任何访问META-INF中资源的请求 目录必须返回SC_NOT_FOUND(404)响应.
因此,从WAR规范中来说,正确的位置是WEB-INF/classes/META-INF.但是,由于war是一个特殊的jar文件,所以将/META-INF作为扩展点很有意义.可以在JPA persistence.xml和Tomcat context.xml文件中看到这种不同的用法:前者应放在WEB-INF/classes/META-INF中,而后者应放在/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
...
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
...
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.
Project Structure
app
|__src/main/java
|__src/main/resources
| |__META-INF
| |__context.xml
...
After mvn package
app
|__META-INF [1]
|__WEB-INF
| |__classes
| |__META-INF [2]
| |__context.xml
...
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?
Regards
So I found this:
Two Meta-Inf folders - normal structure?
which states that having 2 META-INF folders is not a problem. Digging a little I found:
which states about the META-INF folder:
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.
and this:
which, on section 10.6, states about the WAR file structure:
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.
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屋!