java - 在 Eclipse 中创建 META-INF/services 文件夹

标签 java eclipse meta-inf service-provider

我正在尝试用 Java 创建一个可扩展的应用程序并选择使用 SPI。根据这个tutorial我正在关注,我应该在我的 jar 中的 META-INF/services 中创建一个特定文件,但不知道如何。 我知道如何使用 META-INF 创建 jar,但找不到如何创建 services 文件夹和此文件夹中的特定文件的方法。 (我正在使用 Eclipse)

感谢您的帮助。

最佳答案

由于本教程指示手动创建它而不是使用 ant 或 maven 或其他构建工具,因此只需在根级别创建一个名为 META-INF 的文件夹和一个名为 services 和一个名为 MANIFEST.MF 的文件。

我不确定你打算如何执行你的 jar 文件,现在你可以将这一行放在你的 MANIFEST.MF 中:

Manifest-Version: 1.0

对于您的服务文件夹,您需要创建一个名为 com.example.dictionary.spi.Dictionary 的文件,其中包含教程中提到的以下一行内容:-

com.example.dictionary.GeneralDictionary

仅供引用 - META-INF 是一个内部 Java meta 目录。一般情况下,您希望依靠您的打包工具,如 ant 或 maven 来构建 META-INF 文件夹的内容,而不是自己动手。

可以查看META-INF文件夹内容详情here :-

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/

关于java - 在 Eclipse 中创建 META-INF/services 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6376736/

相关文章:

java - 在 Java 中向上转换子类引用

java - 是否可以添加 eclipse 插件 jar 作为 MAVEN 依赖项?

java - Eclipse 与 EGit,git-blame 信息很难看到

java - Eclipse 无法将 enum 识别为关键字

java - 如何将 ascii 流绑定(bind)到准备好的语句

java - 从 swagger 导入后保存会导致 NullPointerException

java - Maven:在 JAR 的 META-INF 中包含文件

java - 无法在 JAR 中找到资源文件

java - 如何使用 java.util.zip 制作 epub

java - SSLv3 和 TLS(v1、v1.1 或 v1.2)能否协同工作