error: null pointer exception in JaxWsDynamicClientFactory

来源:互联网 发布:数据质量 衡量标准 编辑:程序博客网 时间:2024/06/05 20:36

http://stackoverflow.com/questions/15564388/dynamic-client-using-jaxwsdynamicclientfactory-apache-cxf


        问题:

JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();         Client client = clientFactory.createClient("http://172.16.41.6:8085/Logd.asmx?wsdl"); 


原因:

You need to run the code using a JDK, not a JRE. The NPE is happening in the following bit of CXF'sCompiler class

   JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();   StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);

compiler is null if you run in a JRE(java/jre  not java/jdk/jre).

在eclipse中执行代码,默认使用eclipse中指定的jre。若指定的jre不在jdk中,无法找到jdk/bin下的编译器,返回null。CXF'sCompiler中即会出现null pointer exception。



解决:

You need to run the code with a JDK. Bear in mind,some IDEs (eg Eclipse) come with their own compiler and will run in a JRE-only situation.

需要使用JAVA安装目录下面的JDK下面的jre

如果你是eclipse的工程很容易出现不是那个目录。。你可以再windows->preferences->java-Install JRE下面去指定,然后修改工程里的JRE引用到正确的JDK的JRE(右击JRE Library System --> properties --> execution environment下拉表)。

0 0
原创粉丝点击