2017-08-11 15 views
0

私はTibcoプロセスからJavaクラスのメソッドを呼び出しています。このクラスは、DocumentBuilderFactroy抽象クラスを使用します。ファクトリクラスのプロバイダを選択

DocumentBuilderFactroy documentBuilderFactroy = DocumentBuilderFactroy.neInstance(); 

アプリケーションをeclipseでローカルに実行するとすべて正常に動作します。しかし、配布モードでは、私は次のようなエラーがあります。

Provider for javax.xml.parsers.DocumentBuilderFactory can not be created.

をだから私は、実装クラスを指定することで、コード内でdocumentBuilderFactroyオブジェクトをインスタンス化する方法を変更しました。

String providerDBF = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"; 
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance (providerDBF, null); 

私の質問は、ハードコードしないで問題を回避するために実装クラスを指定するにはどうすればいいですか?

私はMavenを使用していません。

ありがとうございました。それが設定することができます

答えて

0

あなたはJREディレクトリにjavax.xml.parsers.DocumentBuilderFactory system propertyまたはproperties fileを使用することができます。 DocumentBuilderFactory documentationから

public static DocumentBuilderFactory newInstance() 

Obtain a new instance of a DocumentBuilderFactory. This static method creates a new factory instance. This method uses the following ordered lookup procedure to determine the DocumentBuilderFactory implementation class to load:

  • javax.xml.parsers.DocumentBuilderFactoryシステムプロパティを使用します。
  • JREディレクトリのプロパティファイル "lib/jaxp.properties"を使用します。 この構成ファイルは、標準のjava.util.Properties形式の であり、実装クラス の完全修飾名を含み、キーは上記で定義されたシステムプロパティです。 jaxp.propertiesファイルはJAXP実装によって一度だけ読み込まれ、 の値は将来の使用のためにキャッシュされます。最初にファイルを読み込もうとしたときにファイルが でない場合は、その存在を確認するためにさらに の試みが行われません。 が最初に読み取られた後に、jaxp.properties内のプロパティの値を変更することはできません。
  • が利用可能であれば、サービスAPI(JAR仕様で詳述)を使用してクラス名を決定します。 Services APIは、 META-INF/services/javax.xml.parsers.DocumentBuilderFactory in jarファイル をjarファイル で実行時に使用できるようにします。
  • プラットフォームのデフォルトのDocumentBuilderFactoryインスタンス。アプリケーション がDocumentBuilderFactoryへの参照を取得すると、 ファクトリを使用してパーサインスタンスを設定して取得できます。
0

JavaDocs状態、:

This method uses the following ordered lookup procedure to determine the DocumentBuilderFactory implementation class to load:

  • Use the javax.xml.parsers.DocumentBuilderFactory system property.
  • Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first attempt is made to read from it, no further attempts are made to check for its existence. It is not possible to change the value of any property in jaxp.properties after it has been read for the first time.
  • Uses the service-provider loading facilities, defined by the ServiceLoader class, to attempt to locate and load an implementation of the service using the default loading mechanism: the service-provider loading facility will use the current thread's context class loader to attempt to load the service. If the context class loader is null, the system class loader will be used.
  • Otherwise, the system-default implementation is returned.
関連する問題