Sujan
Sujan

Reputation: 1562

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.

Upvotes: 2

Views: 5255

Answers (2)

user24185
user24185

Reputation: 31

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

Upvotes: 1

artbristol
artbristol

Reputation: 32407

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.

Upvotes: 3

Related Questions