简体   繁体   English

Eclipse无法识别com.sun.net.httpserver.HttpServer包

[英]Eclipse cant recognize com.sun.net.httpserver.HttpServer package

I have a home-work to create a http server with java , a simple one and from scratch . 我有一个家庭工作用java创建一个http服务器,一个简单的从头开始。 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 搜索谷歌和在这里...我发现这个链接“看到最好的回应”与一个非常好的回应,所以我复制/粘贴这个例子到eclipse,但它无法识别包

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? 另外,如果不是要求很多你知道一些与HttpServer示例的其他链接吗? Thank you in advance ! 先感谢您 !

I had the same problem with Java 8. 我遇到了与Java 8相同的问题。

com.sun.net.httpserver is not API (there is an access restriction, and Eclipse indicate this as error). com.sun.net.httpserver不是API(存在访问限制,Eclipse将此指示为错误)。

You need to add an access rule "Accessible" for the pattern com/sun/net/httpserver/** : 您需要为模式com/sun/net/httpserver/**添加访问规则“Accessible”:

添加访问规则

Related question: Access restriction: Is not accessible due to restriction on required library ..\\jre\\lib\\rt.jar 相关问题: 访问限制:由于对所需库的限制而无法访问.. \\ jre \\ lib \\ rt.jar

It should be available with JDK from 1.6 onwards. 从1.6开始,JDK应该可以使用它。 Otherwise, you can add it your buidpath separately. 否则,您可以单独添加它的buidpath。 Refer below link: 请参阅以下链接:

How to download com.sun.net.httpserver package? 如何下载com.sun.net.httpserver包?

I hit same Issue on Mac OSX 10.8, Eclipse Kepler Service Release 2. I found that it is depends what JVM you use. 我在Mac OSX 10.8,Eclipse Kepler Service Release 2上遇到了同样的问题。我发现它取决于你使用的JVM。 Changing JVM from Apple(Default) to Oracle resolved the issue. 将JVM从Apple(默认)更改为Oracle解决了该问题。

By any chance, are you using Java 5.0? 你有没有机会使用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. 不幸的是,jar没有与Java 5.0 SDK捆绑在一起,您可能希望从此位置下载httpserver jar并将其设置在类路径中。

The simplest solution for this is to go to build path configuration and change the JRE from the default MAC. 对此最简单的解决方案是构建路径配置并从默认MAC更改JRE。 Simply remove the one presented and add the one from your java installation path, for example: 只需删除显示的那个,然后从java安装路径添加一个,例如:

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

When addding new JREs choose Standard VM instead of MacOS X VM 添加新JRE时,请选择标准VM而不是MacOS X VM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM