When to use WEB-INF and when to use META-INF?

In the root of a Java application's archive, you often find the directories WEB-INF and META-INF. Both directories store various metadata files about the application, usually in text formats like YAML, XML, JSON, or plain text.

META-INF is used in archives of all types. The main file in this directory is MANIFEST.MF, which we discussed earlier. It also contains:
  • Declarations of SPI providers;
  • Archive signatures: .SF, .DSA, .RSA files;
  • INDEX.LIST with hints for the loader about the locations of packages.
  • Occasionally (though not often), applications place their static resources here since this directory is included in the classpath and is accessible at runtime.

WEB-INF is used only in web archives (.war). It does not replace but rather complements META-INF. It contains:
  • The main file of the web application, web.xml;
  • Tag descriptor files .TLD;
  • A classes/ subdirectory with the web application's classes;
  • A lib/ subdirectory with .jar dependency libraries;
  • A tag/ subdirectory with tag files.