eclipse 打包为 JAR 后无法创建 SAAJ 元工厂
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47199846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to create SAAJ meta-factory after packaging as JAR
提问by Hakello
For testing an application I am creating SOAP messages. This works when run directly from Eclipse (Oxygen.1a) but after packaging as runnable jar (option: package required libraries into generated jar) I get the following error:
为了测试应用程序,我正在创建 SOAP 消息。这在直接从 Eclipse (Oxygen.1a) 运行时有效,但在打包为可运行的 jar(选项:将所需的库打包到生成的 jar 中)后,我收到以下错误:
javax.xml.soap.SOAPException: Unable to create SAAJ meta-factoryProvider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found
at javax.xml.soap.SAAJMetaFactory.getInstance(SAAJMetaFactory.java:94)
at javax.xml.soap.MessageFactory.newInstance(MessageFactory.java:138)
triggered by:
触发:
MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
So I understand that the MessageFactory uses a sun package
所以我明白 MessageFactory 使用了一个 sun 包
static private final String DEFAULT_META_FACTORY_CLASS =
"com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl";
But I am absolutly clueless as to why it is unable to find this class after packaging to a runnable JAR. Any hints or directions would be greatly apreciated.
但是我完全不知道为什么在打包到可运行的 JAR 后找不到这个类。任何提示或指示将不胜感激。
回答by Manoel Campos
I just added the following dependencyto my project:
我刚刚在我的项目中添加了以下依赖项:
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
If you are using a version older than 1.5.1, you need to create the file META-INF/services/javax.xml.soap.SAAJMetaFactory
with the following line to provide the fully-qualified name of the SAAJ factory class and it worked:
如果您使用的是早于 1.5.1 的版本,则需要META-INF/services/javax.xml.soap.SAAJMetaFactory
使用以下行创建文件以提供 SAAJ 工厂类的完全限定名称并且它有效:
com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl
The javax.xml.soap.saaj-apiseems to be abandoned.
And it's very strange that a package named com.sun
is the one to work.
Anyway, it works.
该javax.xml.soap.saaj-API似乎被抛弃了。很奇怪的是,一个名为的包com.sun
是可以工作的。无论如何,它有效。