Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to create SAAJ meta-factory after packaging as JAR

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:

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

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.

like image 802
Hakello Avatar asked Nov 09 '17 10:11

Hakello


1 Answers

I just added the following dependency to 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:

com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl

The javax.xml.soap.saaj-api seems to be abandoned. And it's very strange that a package named com.sun is the one to work. Anyway, it works.

like image 187
Manoel Campos Avatar answered Sep 18 '22 13:09

Manoel Campos