在Eclipse中创建META-INF / services文件夹 [英] creating META-INF/services folder in Eclipse

查看:3669
本文介绍了在Eclipse中创建META-INF / services文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



感谢您的帮助。

解决方案

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



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

 清单版本:1.0 

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

  com.example.dictionary.GeneralDictionary 

FYI - META-INF 是一个内部Java 目录。一般来说,您希望依靠您的包装工具(如ant或maven)构建META-INF文件夹的内容,而不是自行执行。



您可以看到有关META-INF文件夹的内容的详细信息 here : -

  META-INF目录中的以下文件/目录被Java 2 Platform识别和解释,以配置应用程序,扩展名,加载器和服务器:

MANIFEST.MF

用于定义扩展和包相关数据的清单文件。

INDEX.LIST

此文件由jar工具的新-i选项生成,其中包含应用程序或扩展中定义的软件包的位置信息。它是JarIndex实现的一部分,由类加载器使用,以加快其加载过程。

x.SF

JAR文件的签名文件。 'x'表示基本文件名。

x.DSA

与签名文件相关联的签名块文件具有相同的基本文件名。该文件存储相应签名文件的数字签名。

服务/


I am trying to create an extensible app in Java and chose to use SPI. According to this tutorial I am following, I am supposed to create a specific file in META-INF/services in my jar, but don't know how. I know how to create jar with META-INF, but can't find a way how to create the services folder and particular file in this folder. (I am using Eclipse)

Thanks for your help.

解决方案

Since the tutorial is instructing to create it manually rather than using ant or maven or other build tools then just create a folder named META-INF at the root level with a sub-folder named services and a file called MANIFEST.MF.

I am not sure how you plan to execute your jar file, for now you can just put this one line in your MANIFEST.MF:

Manifest-Version: 1.0

For your services folder, you need to create a file named com.example.dictionary.spi.Dictionary with the following one line content as mentioned in the tutorial:-

com.example.dictionary.GeneralDictionary

FYI - META-INF is an internal Java meta directory. Generally, you want to rely on your packaging tool such as ant or maven to build the content of META-INF folder rather than doing it by yourself.

You can see the details on the content of META-INF folder 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/

这篇关于在Eclipse中创建META-INF / services文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆