Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import javax.xml.bind.annotation.XmlRootElement not resolved

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?

like image 605
Nandish A Avatar asked Jul 10 '13 06:07

Nandish A


People also ask

Is JAXB available in Java 11?

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.

What is @XmlRootElement?

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.

Why is JAXB deprecated?

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.

What does javax XML bind do?

Package javax. xml. bind Description. Provides a runtime binding framework for client applications including unmarshalling, marshalling, and validation capabilities.


2 Answers

Try to synchronize the IDE (Ctrl+Alt+Y)

like image 51
Peter Avatar answered Sep 21 '22 12:09

Peter


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.

like image 22
venkat stark Avatar answered Sep 20 '22 12:09

venkat stark