首先需要在eclipse中建一个java项目,这里不再赘述,可以参考https://blog.csdn.net/cs_hnu_scw/article/details/80181762#commentBox
建好之后运行该类,只运行一次,右键run as---java application,此时不要关闭控制台,即那个红色的按钮不要点击
如果运行了多次,请关闭关于这个java文件全部的console
保证以上步骤成功之后,在浏览器输入http://localhost:9090/MyFirstWebService 会显示
其中wsdl文件可以点进去的。之后
在cmd中输入wsimport -s . http://localhost:9090/MyFirstWebService时报错:
PS D:\java\workspace\webService\src> wsimport -s . http://localhost:9090/MyFirstWebService
parsing WSDL...
[ERROR] Invalid WSDL http://localhost:9090/MyFirstWebService, expected {http://schemas.xmlsoap.org/wsdl/}definitions found html at (line 1)
Failed to read the WSDL document: http://localhost:9090/MyFirstWebService, because 1) could not find the document; /2) the document could not be read; 3) the root element of the document is not <wsdl:definitions>.
[ERROR] failed.noservice=Could not find wsdl:service in the provided WSDL(s):
At least one WSDL with at least one service definition needs to be provided.
Failed to parse the WSDL.
解决:
可能的问题:
1、在命令最后加入 ?wsdl
wsimport -s . http://localhost:9090/MyFirstWebService?wsdl
运行后成功显示:
Generating code...
Compiling code...
PS D:\java\workspace\webService\src>
之后刷新刚才新建的java项目,可以看到在src下生成了很多个java文件,代表成功了
2、将localhost改为你自己主机的ip,重新运行上面的命令
3、换一个端口号试一下,端口号可能被占用