Java 无法在 IntelliJ IDEA 中解析符号“HttpServerFactory”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23682334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot resolve symbol "HttpServerFactory" in IntelliJ IDEA
提问by user3542880
I am trying to create a small project concerning RESTful services. So I fire up IntelliJ IDEA and do:
我正在尝试创建一个关于 RESTful 服务的小项目。所以我启动 IntelliJ IDEA 并执行以下操作:
New Project -> (select Java) -> (select RESTful WebService 2.2) -> check "Generate client and server code", select to download needed libraries.
新建项目->(选择Java)->(选择RESTful WebService 2.2)->勾选“生成客户端和服务器代码”,选择下载需要的库。
Afterwards when going to the created HelloWorld
class I get the following error:
cannot resolve symbol "HttpServerFactory"
as well as cannot resolve symbol "jersey"
for this import: import com.sun.jersey.api.container.httpserver.HttpServerFactory;
.
之后,当转到创建的HelloWorld
类时,我收到以下错误:
cannot resolve symbol "HttpServerFactory"
以及cannot resolve symbol "jersey"
此导入:import com.sun.jersey.api.container.httpserver.HttpServerFactory;
。
Any ideas how to solve this problem?
任何想法如何解决这个问题?
回答by user3246654
Download jersey library via maven solved the problem for me.
通过 maven 下载球衣库为我解决了这个问题。
To create a RESTFul service:
创建 RESTFul 服务:
- Select "New Project"
- Select "Java"
- Check "Application Server" and "RESTFul Web Service"
- Select "Set up library later"
- Click "Next"
- Click "Finish"
- Right-click on the project name
- Select "Add Framework support..."
- Check "Maven" in the list and "Ok"
Add the following lines to the file pom.xml:
<dependencies> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.18.1</version> </dependency> </dependencies>
- 选择“新建项目”
- 选择“Java”
- 勾选“应用服务器”和“RESTFul Web 服务”
- 选择“稍后设置库”
- 点击下一步”
- 点击“完成”
- 右键单击项目名称
- 选择“添加框架支持...”
- 选中列表中的“Maven”并“确定”
将以下行添加到文件 pom.xml 中:
<dependencies> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.18.1</version> </dependency> </dependencies>
回答by Arca Artem
Alternatively, change the version of the Jersey library on your Module settings page. Apparently they removed the HttpServerFactory on later versions...
或者,在模块设置页面上更改 Jersey 库的版本。显然他们在更高版本中删除了 HttpServerFactory ......
To change the version, right click on your module and select 'Open Module Settings (F4)'. From there on click Libraries on the left, select jersey from the library list, then click "Change Version". v1.12 worked for me.
要更改版本,请右键单击您的模块并选择“打开模块设置 (F4)”。从那里单击左侧的库,从库列表中选择球衣,然后单击“更改版本”。v1.12 为我工作。