错误:编码GBK的不可映射字符
基于cxf实现动态调用webservice,打包后运行时cmd中一堆 错误:编码GBK的不可映射字符,编码不一致问题,重写DynamicClientFactory的compileJavaSrc方法指定编码方式即可。下面附上完整源码。
public class JaxWsDynamicClientFactory extends DynamicClientFactory {
protected JaxWsDynamicClientFactory(Bus bus) {
super(bus);
}
@Override
protected EndpointImplFactory getEndpointImplFactory() {
return JaxWsEndpointImplFactory.getSingleton();
}
protected boolean allowWrapperOps() {
return true;
}
/**
* Create a new instance using a specific <tt>Bus</tt>.
*
* @param b the <tt>Bus</tt> to use in subsequent operations with the
* instance
* @return the new instance
*/
public static JaxWsDynamicClientFactory newInstance(Bus b) {
return new JaxWsDynamicClientFactory(b);
}
/**
* Create a new instance using a default <tt>Bus</tt>.
*
* @return the new instance
* @see CXFBusFactory#getDefaultBus()
*/
public static JaxWsDynamicClientFactory newInstance() {
Bus bus = CXFBusFactory.getThreadDefaultBus();
return new JaxWsDynamicClientFactory(bus);
}
/**
* 覆写父类的该方法<br/>
* 注:解决此(错误:编码GBK的不可映射字符)问题
*
* @return
*/
@Override
protected boolean compileJavaSrc(String classPath, List<File> srcList, String dest) {
org.apache.cxf.common.util.Compiler javaCompiler
= new org.apache.cxf.common.util.Compiler();
// 设置编译编码格式(此处为新增代码)
javaCompiler.setEncoding("UTF-8");
javaCompiler.setClassPath(classPath);
javaCompiler.setOutputDir(dest);
javaCompiler.setTarget("1.8");
return javaCompiler.compileFiles(srcList);
}
}
-- Jiay 2019/11/12 18:18
欢迎来访
- 有问题欢迎留言或加交流qq:825121848
- 转载请注明出处
- 请小编喝茶~