加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 06:02:46 所属栏目:Java 来源:网络整理
导读:我试图在 Java中创建一个可扩展的应用程序,并选择使用SPI.根据这个 tutorial我正在关注,我应该在我的jar中的META-INF / services中创建一个特定的文件,但不知道如何. 我知道如何使用META-INF创建jar,但是找不到如何在这个文件夹中创建服务文件夹和特定文件的
我试图在 Java中创建一个可扩展的应用程序,并选择使用SPI.根据这个 tutorial我正在关注,我应该在我的jar中的META-INF / services中创建一个特定的文件,但不知道如何.
我知道如何使用META-INF创建jar,但是找不到如何在这个文件夹中创建服务文件夹和特定文件的方式. (我正在使用Eclipse)

谢谢你的帮助.

解决方法

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

我不知道如何计划执行你的jar文件,现在你可以把这一行放在你的MANIFEST.MF中:

Manifest-Version: 1.0

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

com.example.dictionary.GeneralDictionary

FYI – META-INF是一个内部Java元目录.一般来说,您希望依靠您的包装工具(如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/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读