12

Javaで拡張可能なアプリを作成しようとしていますが、SPIを使用することにしました。私がフォローしているこのチュートリアルによると、私META-INF/servicesは自分のjarファイルに特定のファイルを作成することになっていますが、その方法がわかりません。でjarを作成する方法は知っていますが、このフォルダーにフォルダーと特定のファイルMETA-INFを作成する方法が見つかりません。services(私はEclipseを使用しています)

ご協力いただきありがとうございます。

4

2 に答える 2

12

チュートリアルでは、antやmavenなどのビルドツールを使用せずに手動で作成するように指示されているため、servicesという名前のサブフォルダーとMANIFEST.MFというファイルを使用して、ルートレベルでMETA-INFという名前のフォルダーを作成します。

jarファイルをどのように実行する予定かわかりません。今のところ、この1行を次の行に入れることができますMANIFEST.MF

Manifest-Version: 1.0

com.example.dictionary.spi.Dictionaryサービスフォルダについては、チュートリアルで説明されているように、次の1行の内容で名前が付けられたファイルを作成する必要があります。-

com.example.dictionary.GeneralDictionary

参考までに-META -INFは内部Javaメタディレクトリです。一般に、META-INFフォルダーのコンテンツを自分で作成するのではなく、antやmavenなどのパッケージツールに依存する必要があります。

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/
于 2011-06-16T18:27:59.470 に答える
5

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の「RunnableJarfileexport」を使用してJARファイルを生成する場合は、「Save as ANT script」を選択し、上記のようにサービスにパックするようにantスクリプトを変更します。

于 2011-06-16T18:29:59.083 に答える