6

I just "discovered" that we have two Meta-Inf folders ... In eclipse and also in the War file.

The First one is (in the war):

/META-INF/

The Second, and weird one ist:

/WEB-INF/classes/META-INF/

In the second folder is a persistance.xml and a something.taglib.xml...

If i move the files into the first meta-inf folder i get exceptions from hibernate..

What is the purpose of this second and oddly placed meta-inf folder ?

Is this a normal folder structure ?

Nick Russler
  • 4,608
  • 6
  • 51
  • 88

1 Answers1

7

The "weird one" location is correct; JSR-220/JSR-317 (Java Persistence API 1.0/2.0) in section 6.2/8.2 say:

The jar file or directory whose META-INF directory contains the persistence.xml file is termed the root of the persistence unit. In Java EE, the root of a persistence unit may be one of the following:

  • an EJB-JAR file
  • the WEB-INF/classes directory of a WAR file
  • a jar file in the WEB-INF/lib directory of a WAR file
  • a jar file in the root of the EAR*
  • a jar file in the EAR library directory
  • an application client jar file.

*) Only valid for JPA 1.0

So, directly in a WAR file, the only correct location is WEB-INF/classes/META-INF/.

MaDa
  • 10,511
  • 9
  • 46
  • 84
  • So should i take the content of the 'wrong' one (it contains only the MANIFEST.MF file) and paste that into the 'right' one ? (And then delete the Wrong placed META-INF) – Nick Russler Nov 05 '12 at 23:03
  • 1
    No, the root META-INF is not wrong *per se*, either - it's only not intended to hold the persistence.xml. META-INF/MANIFEST.MF is an archive descriptor of jar/war/ear. This file is the only thing that makes jar/war/ear format different from a plain zip file. – MaDa Nov 06 '12 at 07:27
  • So it is 'normal' or even necessary to have two META-INF's ? – Nick Russler Nov 06 '12 at 15:25
  • 2
    It's certainly normal - whether necessary, I'm not sure. It's just a folder where the "jar" tool puts its metadata, other tools (i.e. Maven) also use it sometimes. – MaDa Nov 06 '12 at 20:58