在Java中,您经常会看到包含一些元文件的meta - inf文件夹。这个文件夹的目的是什么?我可以在那里放什么?
当前回答
Maven中的META-INF
在Maven中,META-INF文件夹被理解是因为标准目录布局,根据名称约定将您的项目资源打包到JAR中:放置在${basedir}/src/main/resources目录中的任何目录或文件都以完全相同的结构打包到JAR中,从JAR的底部开始。
文件夹${basedir}/src/main/resources/META-INF通常包含。properties文件,而在jar中包含一个生成的MANIFEST。MF,砰的一声。属性,pom.xml,以及其他文件。同样,像Spring这样的框架使用classpath:/META-INF/resources/来提供web资源。
有关更多信息,请参阅如何向Maven项目添加资源。
其他回答
如果您使用的是JPA1,则可能必须在其中放入一个persistence.xml文件,该文件指定您可能想要使用的持久化单元的名称。持久化单元提供了一种方便的方式,可以指定一组元数据文件、类和包含分组中要持久化的所有类的jar。
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
// ...
EntityManagerFactory emf =
Persistence.createEntityManagerFactory(persistenceUnitName);
点击这里查看更多信息: http://www.datanucleus.org/products/datanucleus/jpa/emf.html
来自官方JAR文件规范(链接到Java 7版本,但文本至少从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.
自Java 9实现JEP 238以来新增了多版本jar。一个会看到子文件夹的版本。这个特性允许将不同Java版本的类打包到一个jar中。
META-INF文件夹是清单的主页。MF文件。该文件包含关于JAR内容的元数据。例如,有一个名为main - class的条目,它为可执行JAR文件指定了带有静态main()的Java类的名称。
只是在这里添加信息,如果是WAR文件,则是META-INF/MANIFEST。MF文件为开发人员提供了由容器发起部署时检查的工具,以确保容器可以找到应用程序所依赖的所有类。这确保了万一您丢失了一个JAR,您不必等到应用程序在运行时崩溃时才意识到它丢失了。
Maven中的META-INF
在Maven中,META-INF文件夹被理解是因为标准目录布局,根据名称约定将您的项目资源打包到JAR中:放置在${basedir}/src/main/resources目录中的任何目录或文件都以完全相同的结构打包到JAR中,从JAR的底部开始。
文件夹${basedir}/src/main/resources/META-INF通常包含。properties文件,而在jar中包含一个生成的MANIFEST。MF,砰的一声。属性,pom.xml,以及其他文件。同样,像Spring这样的框架使用classpath:/META-INF/resources/来提供web资源。
有关更多信息,请参阅如何向Maven项目添加资源。
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder
- 将JSON字符串转换为HashMap