简体   繁体   English

使用JaxWsDynamicClientFactory(Apache CXF)的动态客户端

[英]Dynamic client using JaxWsDynamicClientFactory (Apache CXF)

I want to make a dynamic client to invoke the web service that I created. 我想创建一个动态客户端来调用我创建的Web服务。 I tried using JaxWsDynamicClientFactory as mentioned in its official site but I am not getting any ouput. 我尝试使用JaxWsDynamicClientFactory ,如其官方站点中所述,但没有得到任何输出。 Instead, I am getting NullPointerException . 相反,我得到了NullPointerException

JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client c = dcf.createClient("http://localhost:8080/service/SearchingSEI?wsdl");

The second line is throwing the exception. 第二行抛出异常。

Stack trace: 堆栈跟踪:

Exception in thread "main" java.lang.NullPointerException
    at org.apache.cxf.common.util.Compiler.useJava6Compiler(Compiler.java:189)
    at org.apache.cxf.common.util.Compiler.compileFiles(Compiler.java:143)
    at org.apache.cxf.common.util.Compiler.compileFiles(Compiler.java:138)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.compileJavaSrc(DynamicClientFactory.java:599)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:367)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)
    at com.client.dynamic.DynamicClientFactory.main(DynamicClientFactory.java:24)

I have no idea what the problem is. 我不知道是什么问题。 Any suggestions would be a great help. 任何建议都会有很大的帮助。 Thanks. 谢谢。

You need to run the code using a JDK, not a JRE. 您需要使用JDK而不是JRE运行代码。 The NPE is happening in the following bit of CXF's Compiler class NPE在CXF的Compiler类的以下位发生

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

compiler is null if you run in a JRE. 如果您在JRE中运行,则compiler为null。

That is because of CXF using JRE7 instead of JDK7. 这是因为CXF使用JRE7而不是JDK7。 When you install JDK in windows, by default JRE also installed and all preferences are pointed to JRE. 在Windows中安装JDK时,默认情况下也会安装JRE,并且所有首选项都指向JRE。

  1. Check your PATH. 检查您的路径。 Make sure it is pointed to ${JDK_LOCATION}/bin 确保它指向$ {JDK_LOCATION} / bin
  2. Check your JAVA_HOME. 检查您的JAVA_HOME。 Make sure it is pointed to ${JDK_LOCATION} 确保它指向$ {JDK_LOCATION}
  3. Go to control panel/java. 转到控制面板/ java。 Add JDK on it. 在其上添加JDK。
  4. You also need to check eclipse in Window->Preference->Java->Installed JREs 您还需要在Window-> Preference-> Java-> Installed JRE中检查eclipse

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM