Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven war has META-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

like image 420
Grasshopper Avatar asked Aug 01 '13 15:08

Grasshopper


People also ask

Where should META-INF folder be?

It shouldn't be at the project root, but directly under the source folder. At runtime, the persistence. xml file is searched in the classpath, under META-INF. So if you want the META-INF folder to be put at the top of the compiled package tree, you need to put it at the top of the source tree.

What is meta-INF in Maven?

The META-INF folder is the home for the MANIFEST. MF file. This file contains meta data about the contents of the JAR. For example, there is an entry called Main-Class that specifies the name of the Java class with the static main() for executable JAR files.

What is the purpose of Meta-INF folder?

The META-INF directory The manifest file that is used to define extension and package related data. This file is generated by the new "-i" option of the jar tool, which contains location information for packages defined in an application or extension.

What is META-INF folder in spring boot?

META-INF is intended to contain the MANIFEST. MF file and the services subdirectory related to the ServiceLoader class, but other frameworks, including Spring, use it as well.


1 Answers

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.

like image 144
Grasshopper Avatar answered Oct 05 '22 19:10

Grasshopper