INF folder in two places

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:

JAR File Specification

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:

JSR-000315 JavaTM Servlet 3.0

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.

链接地址: http://www.djcxy.com/p/74660.html

上一篇: Maven war插件将src / main / webapp复制到类中

下一篇: INF文件夹在两个地方