0

Im trying to use the HttpServer Class from com.sun package but i can't import it. It keeps saying: "The package com.sun is not accessible."

I've tried every solution i could find in other questions about this topic. I've added a rule to have access to it to my libraries. I changed my JDK to another installed JDK17. I don't know what to do anymore. It's for my college homework, so it would be cool to get it running.

Does someone have a clue?

my code problem: my code problem

the access rule: the access rule

my current used jdk: my current used jdk

QuentinC
  • 12,311
  • 4
  • 24
  • 37

1 Answers1

4

You have a module-info.java so you are using Java modules. Consequently you need to say that you are using the jdk.httpserver module which contains com.sun.net.httpserver.HttpServer.

You do that by adding the line:

  requires jdk.httpserver;

to your module-info.java. So something like:

module modulename
{
  requires jdk.httpserver;
}

where modulename is the name of your module.

Alternatively delete the module-info.java file to stop using the module system.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thanks for the advice. i tried both ways and unfortunately adding the line to my module-info.java doesnt do anything and deleting it resulting in "The import com.sun.httpserver cannot be resolved." Does that mean i don't have the necessary .jar-file with the wanted class? i tried download it and added it to my libraries for that java project but its still giving the error message. – SherlockJoe Dec 19 '22 at 15:23
  • Both ways work for me testing here. `jdk.httpserver` should be part of the standard JDK without needing downloads. I'm not sure what the problem is. – greg-449 Dec 19 '22 at 17:09