13

I am rusty on Java and completely new to IntelliJ IDEA, an IDE which has been causing a lot of problems for me so far. I am trying to run a program with the line "import javax.xml.ws.Response;". However, I get the error message "package javax.xml.ws does not exist."

I've tried to select the "Add Java EE 6 JARs to module dependencies" automated solution by IntelliJ IDEA, but it doesn't seem to do anything.

(I believe I am running Java 11, if it makes any difference at all. According to the readme by the author of the code, I should be running Java 8, but so far I haven't been able to because I get an unrelated error when trying to change Java versions with IntelliJ.)

What do I do? Thanks in advance.

AGéoCoder
  • 812
  • 1
  • 10
  • 16
  • 1
    Does the `import` statement also have an error (i.e. is in red) in your source code, or does this error only show up when building? – Tim Biegeleisen Dec 02 '19 at 06:19
  • 6
    Java EE modules [were gone](https://stackoverflow.com/a/48204154/706317) in Java 9. Try adding this dependency: `jakarta.xml.ws:jakarta.xml.ws-api:2.3.2` – ZhekaKozlov Dec 02 '19 at 06:52
  • 1
    @TimBiegeleisen, it shows up in the source code. Unfortunately, the error does not show up consistently with a red lightbulb, a yellow lightbulb, or a pop-up error message on hover. I have an image that is a compilation of three screenshots here: https://imgur.com/a/vY84lBV . Feel free to let me know if the screenshots are helpful at all. (Thank you!) – AGéoCoder Dec 03 '19 at 00:34
  • @ZhekaKozlov, Thank you so much for your reply. Unfortunately, when I tried it I received an unrelated error message, so I was unable to confirm that it works. However, thank you again very very much and I hope you have a great day. – AGéoCoder Dec 03 '19 at 01:13

4 Answers4

14

Your issue is not related to Java version. It will work for both version 8 and 11.

You will need to either download the jaxws-api jar or add it as a Maven dependency accordingly.

You may download the Jar from the below maven repository URL, and then add it to your build path, or update your pom.xml with this dependency: https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api/2.3.1

  • Thank you so much for your reply. Unfortunately, when I tried it I received an unrelated error message, so I was unable to confirm that it works. Thus, I am currently unable to award the "correct answer" checkmark. :( However, thank you again very very much and I hope you have a great day. – AGéoCoder Dec 03 '19 at 01:11
  • 19
    This issue is related to java version! Java 11 has removed this package – Vishal Jul 28 '20 at 08:59
  • 2
    Its related to java version, go to Intellij -> Files -> Project Structure ->. [Here downgrade to java8] – user204069 May 25 '21 at 19:20
6

This is intermittent issue and can eat up hours. Try to do below steps

  1. Remove all dependencies from classpath.
  2. Close the project and open it again.
  3. Add all required dependencies.
  4. Clean your project.
AbhiN
  • 642
  • 4
  • 18
  • Thank you so much for your reply. Unfortunately, when I tried it I received an unrelated error message, so I was unable to confirm that it works. Thus, I am currently unable to award the "correct answer" checkmark. :( However, thank you again very very much and I hope you have a great day. – AGéoCoder Dec 03 '19 at 01:12
4

Go to Project Structure and change Project SDK to Java 1.8 solved my problem

enter image description here

BluEiS
  • 157
  • 1
  • 5
0

I experienced the same error after switching between a Java 11 project and a Java 8 project. IntelliJ is still using JDK 11, which no longer contains the class in question. There are 3 places that IntelliJ could be looking to determine which JDK to use:

  • Under Project Structure, as suggested above by BluEiS
  • Under Settings -> Build, Execution, Deployment -> Gradle (if you're using gradle running from the command line)
  • An environment variable - on Windows, you can add/modify a JAVA_HOME env var pointed to your JDK 8. On Mac, check your gradle.properties to see if there's anything in it that could be overriding your IntelliJ settings