Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of META-INF?

Tags:

java

meta-inf

In Java, you often see a META-INF folder containing some meta files. What is the purpose of this folder and what can I put there?

like image 367
Kristian Avatar asked Sep 16 '08 07:09

Kristian


People also ask

What is META-INF in Android?

Jar files are used by all types of java applications, they have a specific structure - the META-INF folder contains the manifest information and other metadata about the java package carried by the jar file.

Why do you need to delete META-INF?

When you do tamper with it by installing mods, the signature becomes invalid and Minecraft won't start at all. By deleting the META-INF directory, you remove the signature completely. Depending on your security settings, you might get an "unknown publisher" warning, but you'll be able to run it.

What is META-INF 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.

Can I delete META-INF?

You can now delete META-INF without installing any further apps. After this, be sure to rename the .


2 Answers

From the official JAR File Specification (link goes to the Java 7 version, but the text hasn't changed since at least v1.3):

The META-INF directory

The following files/directories in the META-INF directory are recognized and interpreted by the Java 2 Platform to configure applications, extensions, class loaders and services:

  • MANIFEST.MF

The manifest file that is used to define extension and package related data.

  • INDEX.LIST

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. It is part of the JarIndex implementation and used by class loaders to speed up their class loading process.

  • x.SF

The signature file for the JAR file. 'x' stands for the base file name.

  • x.DSA

The signature block file associated with the signature file with the same base file name. This file stores the digital signature of the corresponding signature file.

  • services/

This directory stores all the service provider configuration files.

New since Java 9 implementing JEP 238 are multi-release JARs. One will see a sub folder versions. This is a feature which allows to package classes which are meant for different Java version in one jar.

like image 58
aku Avatar answered Sep 28 '22 04:09

aku


Generally speaking, you should not put anything into META-INF yourself. Instead, you should rely upon whatever you use to package up your JAR. This is one of the areas where I think Ant really excels: specifying JAR file manifest attributes. It's very easy to say something like:

<jar ...>     <manifest>         <attribute name="Main-Class" value="MyApplication"/>     </manifest> </jar> 

At least, I think that's easy... :-)

The point is that META-INF should be considered an internal Java meta directory. Don't mess with it! Any files you want to include with your JAR should be placed in some other sub-directory or at the root of the JAR itself.

like image 31
Daniel Spiewak Avatar answered Sep 28 '22 05:09

Daniel Spiewak