Maven war has META-INF folder in two places
Asked Answered
T

1

18

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

Tenpin answered 1/8, 2013 at 15:5 Comment(0)
T
14

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.

Tenpin answered 2/8, 2013 at 12:41 Comment(2)
A .war file is a .jar file, so it can have META-INF directory just like .jar file.Lombardy
@Lombardy A .war file is a .zip file, just like a .jar file. You can add more files to it so the same file can function as both a .war and a .jar file. This is how Jenkins is distributed jenkins.io/downloadVagal

© 2022 - 2024 — McMap. All rights reserved.