简体   繁体   English

在Eclipse中使用Apache CXF生成Web服务时出现NullPointerException

[英]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/ . 我正在按照本教程在Java Web项目中创建Web服务: 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: 当我开始使用Apache CXF实际生成它时,它会生成所有文件和包(由于某种原因会生成两个jaxws包),但是我在控制台中看到此错误:

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. 我正在阅读: NullPointerException,同时使用Apache CXF生成Web服务 ,但是我的执行环境已经是1.8。

在此处输入图片说明

What am I doing wrong? 我究竟做错了什么? Any help would be appreciated! 任何帮助,将不胜感激!

EDIT: Java class 编辑:Java类

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 并且属于Compiler

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. 似乎您需要Java编译器而不是Java Runtime,请尝试使用JDK而不是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. 如果从命令行运行java2ws,请确保JAVA_HOME环境变量指向最近安装的JDK文件夹,如果您使用的是CXF eclipse插件,则可能还需要降级到Apache CXF 2.7.18,因为CXF eclipse插件不支持3.x版本。

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

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