Eclipse cant recognize com.sun.net.httpserver.HttpServer package
Asked Answered
H

6

15

I have a home-work to create a http server with java , a simple one and from scratch . After searching google and here ...i found this link "see the best response" with a very nice response ,so i copy/paste this example to eclipse , but it doesn't recognize the package

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

can you please help me so i can make eclipse recognize them? Also if isn't asking for to much do you know some other link with a HttpServer example? Thank you in advance !

Hermilahermina answered 31/10, 2012 at 10:21 Comment(2)
this is what i have read on import in eclipse ...Access restriction: The type Headers is not accessible due to restriction on required library /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/rt.jar what did you get ?Spelling
Did you give these suggestions a try #860687Chromaticness
R
3

It should be available with JDK from 1.6 onwards. Otherwise, you can add it your buidpath separately. Refer below link:

How to download com.sun.net.httpserver package?

Ruppert answered 31/10, 2012 at 10:29 Comment(1)
Thank you ,i don't know how i missed that useful link !!After i downloaded the link,i right-clicked to my project and then i clicked on the "Properties" and then "Java build path" and then "Libraries" and then i clicked on the "Add external JAR's.." and then i pointed to the library i downloaded and now all works great .Thank you again for all your help !Hermilahermina
N
56

I had the same problem with Java 8.

com.sun.net.httpserver is not API (there is an access restriction, and Eclipse indicate this as error).

You need to add an access rule "Accessible" for the pattern com/sun/net/httpserver/**:

Add Access Rule

Related question: Access restriction: Is not accessible due to restriction on required library ..\jre\lib\rt.jar

Newson answered 20/9, 2014 at 5:52 Comment(1)
@MarkusL and anyone else wondering the same, see this question: stackoverflow.com/questions/41099332Jaclynjaco
R
3

It should be available with JDK from 1.6 onwards. Otherwise, you can add it your buidpath separately. Refer below link:

How to download com.sun.net.httpserver package?

Ruppert answered 31/10, 2012 at 10:29 Comment(1)
Thank you ,i don't know how i missed that useful link !!After i downloaded the link,i right-clicked to my project and then i clicked on the "Properties" and then "Java build path" and then "Libraries" and then i clicked on the "Add external JAR's.." and then i pointed to the library i downloaded and now all works great .Thank you again for all your help !Hermilahermina
F
2

I hit same Issue on Mac OSX 10.8, Eclipse Kepler Service Release 2. I found that it is depends what JVM you use. Changing JVM from Apple(Default) to Oracle resolved the issue.

Friel answered 16/11, 2014 at 13:16 Comment(0)
C
1

If that fails, change the to version 1.8 of the JRE (Java Runtime Engine). Do this by going to the project's properties. Go to "Java Build Path". Go to the "Libraries" tab. Highlight the JRE library and click "Edit...". Under "System Library" select "Execution environment". From the drop-down list select version 1.8. In my case it was listed as "JavaSE-1.8(jdk-17.0.1)". Click "Finish". Click "Apply and close"

Codger answered 13/2, 2023 at 19:4 Comment(0)
C
0

By any chance, are you using Java 5.0? Unfortunately, the jar doesn't come bundled with a Java 5.0 SDK and you would want to download the httpserver jar from this location and set it in your classpath.

Chromaticness answered 31/10, 2012 at 10:26 Comment(1)
No i am using java 6 for this project and yet nothing ,that's why i wrote here ,it seams strange ,also as @Thanga said im having the exact error , if i download manually the jar where do i have to copy it (i mean the directory on my pc) as i am not used to this kind of things, also thank you for all your help !Hermilahermina
M
0

The simplest solution for this is to go to build path configuration and change the JRE from the default MAC. Simply remove the one presented and add the one from your java installation path, for example:

Library/Java/JavaCirtualMachines/jdk.1.8.0_191.jdk/Contents/Home/bin

When addding new JREs choose Standard VM instead of MacOS X VM

Metz answered 8/6, 2019 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.