Maven war has META-INF folder in two places
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.
Related videos on Youtube
Grasshopper
Former Software Architect with management tendencies, currently a full-time volunteer helping people cope with computers for the first time in their lives through 3G connections in the bushes of Mozambique while trying to train young Mozambicans on how to do the same.
Updated on June 04, 2022Comments
-
Grasshopper almost 2 years
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