I am using intellij and my code uses
import javax.xml.bind.annotation.XmlRootElement;
It compiles and runs when I use command line. However when tried running a test class using the ide(intellij), it gives the error
package javax.xml.bind.annotation does not exists
I have added the jaxb dependency in my pom.xml
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.0</version>
</dependency>
What forces intellij
not to detect this?
With Java releases lower than Java 11, JAXB was part of the JVM and you could use it directly without defining additional libaries. As of Java 11, JAXB is not part of the JRE anymore and you need to configure the relevant libraries via your dependency management system, for example Maven or Gradle.
Annotation Type XmlRootElementMaps a class or an enum type to an XML element. Usage. The @XmlRootElement annotation can be used with the following program elements: a top level class. an enum type.
JAXB was integrated within the JVM itself, so you didn't need to add any code dependency to have the functionality within your application. But with the modularization performed in JDK 9, it was removed as the maintainers wanted to have a smaller JDK distribution that only contains the core concepts.
Package javax. xml. bind Description. Provides a runtime binding framework for client applications including unmarshalling, marshalling, and validation capabilities.
Try to synchronize the IDE (Ctrl+Alt+Y)
Sometimes even after adding the dependencies to the pom.xml file, maven fails to download the dependencies to your local machine. So we can have it downloaded by updating the maven repository.
In case of intelliJ, in the Settings/preference dialog, go to Build, Execution, Deployment -> Build tools -> Maven -> Repositories. On the Repositories page, click Update to update maven repositories.
If you're using eclipse, Right click your project -> maven -> update project. In the update project window, select the recently modified projects and click Ok.
After updating, check if you could import your packages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With