选择工厂供应商 class
Choose provider of a Factory class
我正在从我的 Tibco 进程调用 java class 的方法。此 class 使用 DocumentBuilderFactroy 抽象 class。
DocumentBuilderFactroy documentBuilderFactroy = DocumentBuilderFactroy.neInstance ();
当我在 Eclipse 中本地 运行 应用程序时,一切正常。但是在部署模式下,我有以下错误:
Provider for javax.xml.parsers.DocumentBuilderFactory can not be
created.
所以我改变了代码中实例化documentBuilderFactroy对象的方式,指定实现class。
String providerDBF = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance (providerDBF, null);
我的问题是:如何指定实现 class 以避免在不进行硬编码的情况下出现问题?
我没有使用 Maven。
谢谢。
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.
您可以使用 javax.xml.parsers.DocumentBuilderFactory system property
或 JRE
目录中的 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 格式
并包含实现的完全限定名称 class
键是上面定义的系统属性。这
jaxp.properties 文件只被 JAXP 实现读取一次并且
然后缓存它的值以供将来使用。如果文件没有
当第一次尝试从中读取时存在,不再进一步
尝试检查它的存在。这是不可能的
在 jaxp.properties 中更改任何 属性 的值
第一次看
- 使用服务 API(详见 JAR 规范),如果
可用,以确定 class 名称。服务 API 将查找
文件中的 class 名称
META-INF/services/javax.xml.parsers.DocumentBuilderFactory 在罐子里
可用于运行时。
- 平台默认的 DocumentBuilderFactory 实例。一旦申请
已获得对 DocumentBuilderFactory 的引用,它可以使用
用于配置和获取解析器实例的工厂。
我正在从我的 Tibco 进程调用 java class 的方法。此 class 使用 DocumentBuilderFactroy 抽象 class。
DocumentBuilderFactroy documentBuilderFactroy = DocumentBuilderFactroy.neInstance ();
当我在 Eclipse 中本地 运行 应用程序时,一切正常。但是在部署模式下,我有以下错误:
Provider for javax.xml.parsers.DocumentBuilderFactory can not be created.
所以我改变了代码中实例化documentBuilderFactroy对象的方式,指定实现class。
String providerDBF = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance (providerDBF, null);
我的问题是:如何指定实现 class 以避免在不进行硬编码的情况下出现问题?
我没有使用 Maven。
谢谢。
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.
您可以使用 javax.xml.parsers.DocumentBuilderFactory system property
或 JRE
目录中的 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 格式 并包含实现的完全限定名称 class 键是上面定义的系统属性。这 jaxp.properties 文件只被 JAXP 实现读取一次并且 然后缓存它的值以供将来使用。如果文件没有 当第一次尝试从中读取时存在,不再进一步 尝试检查它的存在。这是不可能的 在 jaxp.properties 中更改任何 属性 的值 第一次看
- 使用服务 API(详见 JAR 规范),如果 可用,以确定 class 名称。服务 API 将查找 文件中的 class 名称 META-INF/services/javax.xml.parsers.DocumentBuilderFactory 在罐子里 可用于运行时。
- 平台默认的 DocumentBuilderFactory 实例。一旦申请 已获得对 DocumentBuilderFactory 的引用,它可以使用 用于配置和获取解析器实例的工厂。