java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException - java

I have created a Web Service using Spring. It works fine when running it on my embedded tomcat server. However when I package it as a JAR file and run it with java -jar command, I am receiving this exception.
My service sends a simple soap request and the server response is:
"exception": "java.lang.NoClassDefFoundError",
"message": "javax/xml/soap/SOAPException",
That's the response I get in Postman.
Any ideas where I can look for the problem.

Adding the following in pom file solved the issue
<!-- https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api -->
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.4.0</version>
</dependency>

JavaSE 8 includes package java.xml.soap.
JavaSE 9 moved package javax.xml.soap to the module java.xml.ws.
Modules shared with JEE (like java.xml.ws) are included in JavaSE 9, but are
- deprecated for removal from a future version of JavaSE, and
- not on the default module path.
A quick workaround is to either
- run the jar with JRE 8: $MY_JRE8_HOME/bin/java -jar my.jar, or
- add a module for JRE 9: java --add-modules java.xml.ws -jar my.jar
Longer term, JavaSE projects that use modules like java.xml.ws must explicitly include the module like other libraries.
See https://stackoverflow.com/a/46359097
See JDK 9 Migration Guide: Modules Shared with JEE Not Resolved by Default
(Reproduced NoClassDefError and workarounds with zipped SOAP web service project at https://spring.io/guides/gs/producing-web-service/)

Yes, In Java 11 java.xml.soap was completely removed.
java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException can be removed by adding the
following dependency.
<dependency>
<groupId>jakarta.xml.soap</groupId>
<artifactId>jakarta.xml.soap-api</artifactId>
<version>2.0.0-RC3</version>
</dependency>
But later, you will encounter , javax.xml.soap.SOAPException: Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found.
This can be solved by adding the following dependency.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
Hope, it helps!

Add the following dependencies, it should work then
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.6</version>
</dependency>
Refer the following links for a running piece of code (SpringBootSOAPWS + Java10)
Github- SpringBoot Soap Server
Github- SpringBoot Soap Client

I imported this one to sort out the issue: https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api/1.4.0

Adding this dependency will solve the issue.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.0</version>
</dependency>

The JAX-WS dependency library “jaxws-api.jar” is missing.
Try:
compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1' - for gradle or:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>

I know this is already closed for all above people but I am still facing this issue even though I have added
jakarta-xml.soap-api and saaj jars in classpath.
Anything that I am missing to make it work.Tried out using javax-.xml-soap-api as well instead of jakarta jar but still same error.Somehow its not able to identify the jar.

Related

JDK 11: java.lang.NoClassDefFoundError: javax/xml/ws/handler/soap/SOAPHandler

We are migrating to openjdk 11 from jdk 8. Some of our projects that uses soap to call third party apis are failing with error:
java.lang.NoClassDefFoundError: javax/xml/ws/handler/soap/SOAPHandler
After doing some research, I tried by adding dependencies :
[
references:
How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9
Replacements for deprecated JPMS modules with Java EE APIs
]
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.3.5</version>
</dependency>
Did not work. may I get an idea on the alternatives?
Include jaxws-api in your dependencies:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
The javax APIs were transitioned to Jakarta, so in 2020 the proper dependency is the following:
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>2.3.3</version>
</dependency>
Here's an article summarizing what happened:
Java Magazine - Transition from Java EE to Jakarta EE
And here's a very useful table with mappings between the old artifacts and the new one.
Since this is the first result on google, my issue was due to having a jar, that required javax.xml.ws classes, on the Tomcat common folder /usr/local/tomcat/lib.
The Tomcat classloader hierarchy is
Bootstrap
|
System
|
Common
/ \
Webapp1 Webapp2 ...
On Java 8 the common classloader can load these classes since they are on Java JRE itself, but on Java 11, the javax.xml.ws classes are on Webapp1, and the Tomcat common classloader can not load these.
For me, the solution was to no longer deploy the jar into the Tomcat common lib folder.

Unable to create SOAP connection factory: Provider com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnectionFactory not found

I am currently developping a Java server app that connect to another server with SOAP, retrieve some data and store it into a DB.
I work on Eclipse Photon, Maven project.
My Soap client worked perfectly fine until now. For my db storage functions, I needed the JDBC SQL Server driver. But Eclipse told me that driver was compiled with a more recent version of Java.
I was on Java 8, I updated to Java 10 and now the driver works fine BUT my SOAP client doesn't work anymore ! Eclipse doesn't recognize the import javax.xml.soap I use for my Soap.
So I put into my pom.xml some dependencies for it like :
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api -->
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.4.0</version>
</dependency>
The import of javax seemed to be recognized again by Eclipse so I compiled my project with Tomcar to launch it and after trying my Soap client it gives me the following error :
java.lang.Exception: Unable to create SOAP connection factory: Provider com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnectionFactory not found
Adding this dependency to my POM fixed the issue:
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.4.0</version>
</dependency>
It also fixes this error: javax.xml.soap.SOAPException: Unable to create message factory for SOAP: Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found
I had this same scenario, here's how I fixed it:
I downloaded the saaj-impl jar and the mimepull dependency
https://jar-download.com/artifacts/com.sun.xml.messaging.saaj/saaj-impl/1.3.6/source-code
I imported these two jars into intelliJ as a dependency via File -> Project Structure -> Modules -> Dependencies
Then I added the maven dependencies into pom.xml:
<!-- saaj-impl-1.3.16.jar maven dependency -->
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>LATEST</version>
<systemPath>${project.basedir}/(from project folder to jar file).../saaj-impl-
1.3.16.jar</systemPath>
<scope>system</scope>
</dependency>
<!-- mimepull-1.7.jar maven dependency -->
<dependency>
<groupId>org.jvnet.mimepull</groupId>
<artifactId>mimepull</artifactId>
<version>LATEST</version>
<systemPath>${project.basedir}/(from project folder to jar file).../mimepull-
1.7.jar</systemPath>
<scope>system</scope>
</dependency>
After closing the project and reopening, I stopped getting the missing soapconnectionfactory class error!

JAVA - com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found

I'm working on an application that consumes a web service using SOAP requests.
Sometimes I get this error:
filters.LoggerFilter:92 - org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.Error: javax.xml.soap.SOAPException: Unable to create SAAJ meta-factoryProvider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found
The weird part is that I get this error randomly, but I can't seem to figure out the cause.
I even added a new dependency, but it doesn't seem to correct the issue:
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
</dependency>
I just had the same problem while using Java 11 to create an application that consumes SOAP-requests.
I added the new dependency and it worked fine for me.
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
For me, I was using Java 13 and the following worked for me(add these in the pom.xml)
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-rt</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-api</artifactId>
<version>2.4.4</version>
</dependency>
For those who face this issue in intellij IDEA using Spring Boot under Java SDK 9+, you have to include explicitly --add-modules java.se.ee in VM parameters (edit configurations -> VM options). This answer may help to resolve other importing issues related to new Java Modules
I had the same problem.
For me, adding saaj-impl was not enough to get rid of the exception
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.2</version>
</dependency>
I had to also add saaj-api which fixed it finally:
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3.5</version>
</dependency>
Since I realised that my application was using saaj-api 1.3.4 after checking with command, upgrading to 1.3.5 helped
mvn dependency:tree -Dverbose
Change your project sdk as Java 1.8
If you are using import javax.xml.ws library it could be confusing com.sun.xml.messaging.saaj dependency in Java 11. Clearing saaj dependency then using Java8 may be a solution in this issue
With open JDK 17 and spring boot 3.0.1, I was getting the same issue. It got resolved by adding these dependencies in pom.xml
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-rt</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-api</artifactId>
<version>2.4.4</version>
</dependency>

java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream

I'm trying to send an email through Java Mail API and it works fine on my laptop. When I'm doing exactly the same in Heroku, I'm getting this:
java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream.(Ljava/io/InputStream;Lcom/sun/mail/util/MailLogger;)V
at com.sun.mail.smtp.SMTPTransport.initStreams(SMTPTransport.java:2014)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1936)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:291)
at ...
Here is what I have in pom.xml:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mailapi</artifactId>
<version>1.4.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.3</version>
<scope>runtime</scope>
</dependency>
I guess there is another version of Java Mail API inside Heroku JDK, which doesn't have this constructor... How can this be fixed?
By default, Java apps running on latest Heroku stack use OpenJDK 8.
Your problem does not seems related to the actual JVM implementation but rather due to the missing smtp-1.5.1.jar in classpath . To be sure to load correctly TraceInputStream try this :
java.net.URL classUrl = this.getClass().getResource("com.sun.mail.util.TraceInputStream");
out.println(classUrl.getFile());
I also faced the same issue. It was because I don't have the class TraceInputStream inside the library. I simply downgrade libraries to 1.4.4 and it worked.
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>smtp</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>mailapi</artifactId>
<version>1.4.4</version>
</dependency>
You've mixed different versions of the API and implementation; don't do that. For that matter, you only need the com.sun.mail:javax.mail dependency. If Heroku isn't providing it in the runtime environment, you'll need to package it in your application. Make sure the JavaMail jar file is ending up in the WEB-INF/lib directory of your application.
Getting reference from #Osanda Deshan. Adding below gradle dependencies Worked for me.
implementation 'javax.mail:javax.mail-api:1.4.4'
implementation 'javax.mail:mail:1.4.4'

Maven dependencies for REST API - Jersey - Glassfish or not?

I'm new to REST API and little familiar with Maven. I noticed that most people use REST with Jersey implementation. I need to write POST requests and might also need GET requests as well. I have difficulty finding out the right - minimum required - dependencies for Maven to start coding.
I looked at many resources online. Looks like Jersey comes with Glassfish Server. I have Tomcat installed on my local PC which I'm going to use for development of REST and testing. We have Jboss running on our production servers which my code eventually will be deployed to. It looks to me that different resources say different things or there are chances I'm not getting it!
1) Can I use Jersey with Tomcat or Jboss WITHOUT any dependency on Glassfish?
2) Back to the Maven dependencies;
Here I found:
http://aike.me/site/blog/20090914/restful_web-services_in_java_using_jax-rs_-_part_1_getting_up_and_running
Maven: Getting Jersey into your project
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.0.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
Are these would be ALL I need?
B/c in Jersey website I found different dependencies defined:
https://jersey.java.net/documentation/latest/modules-and-dependencies.html
I won't copy and paste those dependencies here b/c it makes this post very long. I do NOT see any of these dependencies - mentioned in http://aike.me defined in:
https://jersey.java.net
Such as:
<artifactId>jersey-server</artifactId>
<artifactId>jaxb-impl</artifactId>
<artifactId>jsr311-api</artifactId>
<artifactId>jaxb-api</artifactId>
Why is that? Why I'm being referred to different dependencies?
Any help is greatly appreciated.
Using a dependency with "org.glassfish.*" in group id doesn't mean you have to use Glassfish server.
Jersey has become a part of glassfish and that's the only reason the package name has changed. The newest versions are released under this package and it is recommended on the Jersey website so I would stick with the newest packages.
I have created a quick start template for the same, feel free to fork or clone it.
Get it here

Categories

Resources