EclipseでMeta-INF/Servicesフォルダーを作成します
-
28-10-2019 - |
質問
Javaで拡張可能なアプリを作成しようとしており、SPIを使用することを選択しました。これによれば チュートリアル 私はフォローしています、私は特定のファイルを作成することになっています META-INF/services
私の瓶では、方法がわかりません。ジャーを作成する方法を知っています META-INF
, 、しかし、作成する方法が見つかりません services
このフォルダーのフォルダーと特定のファイル。 (私は日食を使用しています)
ご協力いただきありがとうございます。
解決
チュートリアルは、アリやメイベン、または他のビルドツールを使用するのではなく、手動で作成するように指示しているため、名前のフォルダーを作成するだけです メタ-INF ルートレベルで、サブフォルダーという名前が付いています サービス と呼ばれるファイル manifest.mf.
JARファイルをどのように実行するかわからないので、今のところ、この1行をあなたの中に置くことができます MANIFEST.MF
:
Manifest-Version: 1.0
サービスフォルダーの場合、名前のファイルを作成する必要があります com.example.dictionary.spi.Dictionary
チュートリアルで述べたように、次の1つの行コンテンツを使用して: -
com.example.dictionary.GeneralDictionary
ご参考までに - メタ-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のアリを含む瓶ファイル, 、metainfファイルセットを追加する必要があります。
<jar jarfile="pinky.jar">
<fileset dir="build/classes"/>
<service type="javax.script.ScriptEngineFactory"
provider="org.acme.PinkyLanguage"/>
</jar>
Apacheのアリを使用しない場合は、瓶にファイルを追加する必要があります
jar -uf jarfile.jar META-INF/services/name.of.general.service
サービスの実装の名前が含まれています
com.mycorp.services.Fooservice
プロジェクトの下でEclipseの「実行可能なJARファイルエクスポート」を使用してJARファイルを生成している場合は、「ANTスクリプトとして保存」を選択し、上記のようにANTスクリプトを変更してサービスに詰めます。