本人维护公司以前的一个项目,这个项目要调用另外一个项目的单点登录接口。代码如下:
String AuthServiceUrl = "http://portal.gf.com.cn/app/GFNotification/restful/GFCommonService/";// 用户身份校验API地址 try { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(AuthServiceUrl); ClientResponse response = service.path("mixModeUserLoginAuth/ccbm/ccbm/lihl/a123456") .type(MediaType.APPLICATION_XML_TYPE).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); RestfulResult erprs = response.getEntity(RestfulResult.class); System.out.println("CALL Result:" + erprs.isSuccess()); System.out.println("CALL Result Msg:" + erprs.getMsg()); } catch (Exception e) { System.out.println(e); }
问题:上面这段代码要用到哪些jar包?
本人已经引用如下jar包,如下图所示:
报错信息如下:
APPLICATION_XML_TYPE cannot be resolved or is not a field RestfulResult cannot be resolved to a type
请大神赐教,感激不尽!
问题:上面这段代码错在哪里,我是否引用错了jar包?
问题1:如果不考虑引入jar包版本问题,会不会出现各个依赖jar版本不兼容报错问题?
问题2:通常应该去哪里找项目需要的jar?因为,我觉得根据项目代码去百度搜索jar效率太低,容易出错。
管理jar包建议使用maven吧,这样可以保证一个项目用的jar包版本是一样的
jar包引用的问题吧
这一行:
RestfulResult erprs = response.getEntity(RestfulResult.class);
你用了一个RestfulResult
,这是个没有import的类,这个类可能是你们公司其他人定义的。找到定义的代码,import进来就可以了。
找jar包我一般去 http://mvnrepository.com/