29

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.

Hakello
  • 457
  • 1
  • 5
  • 10
  • Do you have this class "com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl" in jar file or in classpath? – Michal Lonski Nov 09 '17 at 10:54
  • If I include the referenced file as as jar file (https://mvnrepository.com/artifact/com.sun.xml.messaging.saaj/saaj-impl/1.3) it works after beeing packaged. So to rephrase: I do not understand why it works in eclipse without that library. – Hakello Nov 09 '17 at 12:07
  • 1
    Probably eclipse has its own classpath built. You can try print it at the runtime and compare the results. – Michal Lonski Nov 09 '17 at 12:12
  • Well @Michal, you are on to something... I could not run the sample that prints the classpath on runtime after packaging it to a JAR either (eclipse ran fine)... So I uninstalled JDK 9. Both the classpath thing and the actual SOAP call work great on the latest JDK8 (which eclipse still had as default). – Hakello Nov 09 '17 at 12:27
  • I got this error when switching to Java 11. https://stackoverflow.com/questions/54573998/java-11-package-javax-xml-soap-does-not-exist – Evgeny Artemev Dec 18 '19 at 09:37

7 Answers7

52

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.

Manoel Campos
  • 933
  • 9
  • 12
  • 9
    I tested this, porting from Java 8 to JDK 11. It solved the problem, running in Tomcat 9 – mico Oct 26 '18 at 08:18
  • Where did you find out that `javax.xml.soap.saaj-api` is depecated? – Jorge Yanes Diez Nov 07 '18 at 10:58
  • 2
    I am in a similar situation to @mico, upgrading from 1.6 to 11 and Tomcat 7/GlassFish 3 to Tomcat9. This answer almost did the trick for me, but I kept getting `org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR` exceptions. The problem went away when I downgraded `saaj-impl` to version `1.3`. See [this answer](https://stackoverflow.com/questions/3184268/org-w3c-dom-domexception-wrong-document-err-a-node-is-used-in-a-different-docu) – Jorge Yanes Diez Nov 07 '18 at 11:42
  • @JorgeYanesDiez, I said it seems to be deprecated. The `com.sun.xml.messaging.saaj.ssaj-impl` was updated in Oct, 2018 and the javax.xml.soap.saaj-api in Mar, 2013. And using the `javax.xml.soap.saaj-api`, it doesn't work. – Manoel Campos Nov 08 '18 at 13:07
  • 2
    Note that if you update to the 1.5.1 version of the jar, there is no requirement to create the META-INF/services/javax.xml.soap.SAAJMetaFactory file – tanderson Mar 07 '20 at 23:11
  • I applied the answer but was not enough. It was fixed for me after I added saaj-api (1.3.5 version) along with saaj-impl (1.5.2) – bahadir_g Aug 30 '20 at 16:47
  • This link was helped: https://stackoverflow.com/a/56633929/8378668 – HenryGuillen17 Aug 31 '20 at 01:02
  • This worked for me. I was facing the issue while consuming a SOAP API inside my app (SpringBoot war) running in Tomcat 8.5 and JRE 8. SpringBoot App which is on JDK 1.8 was successfully consuming the SOAP API but when deployed to Tomcat was giving this errors. – nirmalsingh Aug 09 '21 at 11:51
3

After switching my jdk to 11,I had same problem. Uppgrading apache.cxf jar to 3.5.1 solved my problem.Was using 3.1.2 with jdk 1.8

Arif K.
  • 45
  • 7
2

I'm using Java 11 and in addition to the

implementation group: 'com.sun.xml.messaging.saaj', name: 'saaj-impl', version: '1.5.2'

add

implementation group: 'javax.xml.soap', name: 'javax.xml.soap-api', version: '1.4.0'

but necessarily turn off implementation group: 'com.sun.xml.messaging.saaj', name: 'saaj-impl', version: '1.5.2'

Eugene
  • 21
  • 2
1

I'm using Spring Boot 2.4.0 and Java 11. This is what worked for me:

implementation 'javax.xml.ws:jaxws-api:2.3.1'
implementation 'javax.jws:javax.jws-api:1.1'
implementation 'com.sun.xml.messaging.saaj:saaj-impl:1.5.1'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.2'
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
0

I have solved the problem by adding the following two dependencies

   <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>1.5.1</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.soap</groupId>
        <artifactId>saaj-api</artifactId>
        <version>1.3.5</version>
    </dependency>
Arturo Bernal
  • 31
  • 1
  • 1
0

The answers above (adding saaj-impl and saak-api) work for most projects, but I found out that if your project has a dependency on javax.xml webservices-api, you also need to remove that dependency in order to stop getting that error in Java 11.

Exemple of the dependency to remove in Maven :

   <dependency>
     <groupId>javax.xml</groupId>
     <artifactId>webservices-api</artifactId>
     <version>2.0.1</version>
   </dependency>
user327961
  • 2,440
  • 3
  • 22
  • 20
0

If you are using Weblogic, change the value of the parameter prefer-web-inf-classes at weblogic.xml file. It worked for me.

RusJaI
  • 666
  • 1
  • 7
  • 28
esarregui
  • 1
  • 1