简体   繁体   中英

NullPointerException when generating webservice with Apache CXF in Eclipse

I am following this tutorial to create a web service in a Java web project: https://angelozerr.wordpress.com/2011/08/24/jaxwscxf_step2/ . When I get to actually generating it with Apache CXF, it makes all the files and packages (makes two jaxws packages for some reason), but I see this error in the console:

java2ws -cp C:\Users\mo\Documents\Workspace\NpcWS\build\classes -s C:\Users\mo\Documents\Workspace\NpcWS\.cxftmp/src -d C:\Users\mo\Documents\Workspace\NpcWS\.cxftmp/wsdl -classdir C:\Users\mo\Documents\Workspace\NpcWS\build\classes -o helloserviceimpl.wsdl -createxsdimports -verbose -frontend jaxws -databinding jaxb -wsdl -wrapperbean org.cloudlet.ws.HelloServiceImpl
java2ws - Apache CXF 3.1.6

May 26, 2016 9:18:55 AM org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://ws.clodulet.org/}HelloServiceImplService from class org.clodulet.ws.HelloServiceImpl
java.lang.NullPointerException
    at org.apache.cxf.common.util.Compiler.useJava6Compiler(Compiler.java:187)
    at org.apache.cxf.common.util.Compiler.compileFiles(Compiler.java:141)
    at org.apache.cxf.tools.java2wsdl.generator.wsdl11.BeanGenerator.generateAndCompile(BeanGenerator.java:91)
    at org.apache.cxf.tools.java2wsdl.generator.wsdl11.BeanGenerator.generate(BeanGenerator.java:58)
    at org.apache.cxf.tools.java2wsdl.generator.wsdl11.BeanGenerator.generate(BeanGenerator.java:35)
    at org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor.generate(JavaToWSDLProcessor.java:156)
    at org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor.process(JavaToWSDLProcessor.java:118)
    at org.apache.cxf.tools.java2ws.JavaToWSContainer.processWSDL(JavaToWSContainer.java:110)
    at org.apache.cxf.tools.java2ws.JavaToWSContainer.execute(JavaToWSContainer.java:75)
    at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)
    at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:58)
    at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:40)
    at org.apache.cxf.tools.java2ws.JavaToWS.run(JavaToWS.java:77)
    at org.apache.cxf.tools.java2ws.JavaToWS.main(JavaToWS.java:45)

I was reading this: NullPointerException while generating web service with Apache CXF , but my execution environment is already 1.8.

在此处输入图片说明

What am I doing wrong? Any help would be appreciated!

EDIT: Java class

package org.clodulet.ws;

import javax.jws.WebService;

@WebService(targetNamespace = "http://ws.clodulet.org/", portName = "HelloServiceImplPort", serviceName = "HelloServiceImplService")
public class HelloServiceImpl 
{
    public String getVersion() {
        return "1.0";
    }

    public String hello(String str) {
        return "Hello " + str;
    }
}

These are the files it creates: (then the error shows up)

在此处输入图片说明

Looking at the exception trace,

java.lang.NullPointerException
    at org.apache.cxf.common.util.Compiler.useJava6Compiler(Compiler.java:187)

and part of the Compiler class

180        Object compiler = Class.forName("javax.tools.ToolProvider")
181            .getMethod("getSystemJavaCompiler").invoke(null);

seems like you need the Java Compiler, not the Java Runtime, try running it with JDK not JRE.

If you are running java2ws from command line, ensure that your JAVA_HOME environment variable is pointing to the recently installed JDK folder, if you are using the CXF eclipse plugin you may also need to downgrade to Apache CXF 2.7.18, because the CXF eclipse plugin does not support 3.x versions.

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