Eclipse cant recognize com.sun.net.httpserver.Http

2019-02-12 16:28发布

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 !

4条回答
劳资没心,怎么记你
2楼-- · 2019-02-12 16:48

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.

查看更多
我命由我不由天
3楼-- · 2019-02-12 16:55

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?

查看更多
Evening l夕情丶
4楼-- · 2019-02-12 17:13

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.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-02-12 17:15

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

查看更多
登录 后发表回答