14

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?

Nandish A
  • 1,645
  • 5
  • 26
  • 41

6 Answers6

2

Maybe you can check intellij , in the Project Structure dialog, go to Project Settings -> Project -> Project SDK , choose other version SDK like 1.8 and click OK

calm
  • 33
  • 5
1

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

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Peter
  • 5,556
  • 3
  • 23
  • 38
1

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.

1

In case anyone else ends up here. My dependency scope was listed as 'runtime' and changing it to 'provided' meant it downloaded the dependency

I'm coming from a python background and trying to debug something and have no idea what i'm doing though, so hopefully i haven't created a major issue... (this issue talks a bit about the difference)

<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>2.3.0</version>
  <scope>runtime</scope>
</dependency>

to:

<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>2.3.0</version>
  <scope>provided</scope>
</dependency>
scvbelle
  • 21
  • 2
0

with Eclipse Spring boot i only use

     <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
    </dependency>

Reason? my coworker delete swagger jar

Yurifull
  • 373
  • 2
  • 5
0

The issue is with javax vs jakarta


Try using this dependency

    <!-- https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api -->
<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>4.0.0</version>
</dependency>
gprem062
  • 11
  • 3
  • This doesn't really answer the question - his dependency works fine, it's the IDE that fails. – Chaoz Mar 03 '23 at 04:06
  • @Chaoz did you try this dependency instead of that one? Coz I was facing the same issue but this one works fine. – gprem062 Mar 15 '23 at 12:54