简体   繁体   中英

Dynamic client using JaxWsDynamicClientFactory (Apache CXF)

I want to make a dynamic client to invoke the web service that I created. I tried using JaxWsDynamicClientFactory as mentioned in its official site but I am not getting any ouput. Instead, I am getting 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. The NPE is happening in the following bit of CXF's Compiler class

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

compiler is null if you run in a JRE.

That is because of CXF using JRE7 instead of JDK7. When you install JDK in windows, by default JRE also installed and all preferences are pointed to JRE.

  1. Check your PATH. Make sure it is pointed to ${JDK_LOCATION}/bin
  2. Check your JAVA_HOME. Make sure it is pointed to ${JDK_LOCATION}
  3. Go to control panel/java. Add JDK on it.
  4. You also need to check eclipse in Window->Preference->Java->Installed JREs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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