前情回顾:
我在linux环境下执行以下逻辑时
public RPCResult<Serializable> callRemoteMethod(String url, String methodName, String body) {
log.info("cxf发送:{}",body);
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
Client client = (Client) clientFactory.createClient(url);
try {
Object[] result = client.invoke(methodName,body);
log.info("cxf返回:{}", JSONObject.toJSONString(result));
return super.success(result);
} catch (Exception e) {
String errorMsg = "cxf接口发送失败:" + e.getMessage();
log.error(errorMsg, e);
return RPCResult.buildFail(errorMsg);
}
}
报了以下错误:
解决过程:
我们通过日志打印找到了createSchemaCompilerWithDefaultAllocator方法
我们再来看一下createSchemaCompiler这个方法
我们可以看到是在加载com.sun.tools.xjc.api.XJC这个类的时候发生了错误。我们看到这个类是在tools.jar下,但是我们项目启动是jre环境启动的,jre环境不包含tools.jar。当然jdk环境一般情况下都会有tools.jar,低版本或者一些版本也是没有tools.jar的情况。
我们就换成了jdk环境启动项目。最终这个问题迎刃而解。