繁体   English   中英

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

[英]creating META-INF/services folder in Eclipse

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

谢谢你的帮助。

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

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

Manifest-Version: 1.0

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

com.example.dictionary.GeneralDictionary

仅供参考 - META-INF是一个内部Java 目录。 通常,您希望依靠诸如ant或maven之类的打包工具来构建META-INF文件夹的内容,而不是自己动手。

您可以在此处查看有关META-INF文件夹内容的详细信息: -

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/

假设您使用Apache的Ant构建jar文件 ,您需要添加一个metainf文件集,或者更好的是,使用像这样的服务指令

<jar jarfile="pinky.jar">
  <fileset dir="build/classes"/>
  <service type="javax.script.ScriptEngineFactory"
           provider="org.acme.PinkyLanguage"/>
</jar>

如果你不使用apache的Ant,那么你需要在jar中添加一个文件

jar -uf jarfile.jar META-INF/services/name.of.general.service

其中包含服务实现的名称

com.mycorp.services.Fooservice

如果使用项目下的Eclipse“Runnable Jar文件导出”生成JAR文件,请选择“另存为ANT脚本”,然后修改ant脚本以打包服务,如上所述。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM