微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我试图在 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/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐