package javax.xml.bind.annotation does not exist error [duplicate] - java

This question already has an answer here:
Java 11 package javax.xml.bind does not exist [duplicate]
(1 answer)
Closed 1 year ago.
I am trying to run "mvn clean install" command, but I get the following error:
java:[42,22] package javax.xml.bind does not exist
Do you have any idea why?

Try adding
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
into your pom.xml file

The library javax.xml.bind has been removed from Java 11 release.
Release Notes
For fixing this you have add those dependencies explicitly in your POM file or add it to your classpath accordingly.
<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.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
After adding it to your POM you can build the maven project. First time you can skip tests.
mvn clean install -DskipTests

Download jaxb API jar file, and add it as an external jar to the Java build path.

Related

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!

Not able to find artifact jackson-modules-java8 jar

I am using pom.xml like
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
but there is no .jar available in public repo. It have only .pom file in respective release. Public maven repository link
How to get .jar for it.
You can manually download .zip for respective release from jackson-modules-java8/releases
and build it locally using command.
mvn clean install
It will give you .jar for each module under respective target directory.
You need to also include that dependency in your pom.xml:
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-modules-java8</artifactId>
<version><!-- same version as your other jackson dependencies --></version>
</dependency>

How to replace --add-modules java.xml.ws

I did migrate my Maven based project to SpringBoot 2.0 and Java 9. In the process, I had to add some dependencies to get rid of Java 9 warnings regarding modules (that still can be added with --add-modules).
However I am unable to get rid off --add-modules java.xml.ws. As suggested in JEP 320, adding dependencies:
<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-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
These dependencies allow to run mvn test to run through. The build from IntelliJ IDE also works.
However when starting the Spring Boot application, I get the following runtime exception:
...
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:174)
... 64 more
What Maven dependencies am I missing? JarFinder tells me that the implementation class is part of jaxb-impl, but only up to version 2.2.12. So where did this implementation disappear to?
You need also jaxb-runtime:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0</version>
</dependency>
And I don't think you need any of the com.sun dependencies, use glassfish ones for the implementation:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
As a side note, I think it is good to have at least one integration test (maven failsafe one) that starts the spring context. If you will have one make sure you use at least surefire and failsafe 2.21.0 (previous version had a bug with --add-modules).

Spring Boot 2 project works in IDE but not command line

I am running a Spring Boot project. I can run the project from IntelliJ, however when I try and do mvn spring-boot:run I get java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
I have included
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
in my pom.xml file. I have even included java.xml.bind as an add modules in the pom. But the issue still persists. What am I missing?
Credit to #jny for the answer
I had the wrong dependency in the pom file. Replacing it with
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
corrected the issue.

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

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.

Categories

Resources