簡體   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