如何使用 Eclipse 将 WSDL 转换为 Java 类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22460571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you convert WSDLs to Java classes using Eclipse?
提问by khris
I have a WSDL file (or, more precisely, its URL). I need to convert it to Java classes. I also need to provide tests for the web service it describes. I'm new to web services, so could someone tell me how to convert WSDLs to Java?
我有一个 WSDL 文件(或者更准确地说,是它的 URL)。我需要将其转换为 Java 类。我还需要为其描述的 Web 服务提供测试。我是 Web 服务的新手,有人能告诉我如何将 WSDL 转换为 Java 吗?
I use Eclipse JEE Kepler. Maybe there are some plugins to do this automatically?
我使用 Eclipse JEE 开普勒。也许有一些插件可以自动执行此操作?
采纳答案by Ashok_Pradhan
In Eclipse Kepler it is very easy to generate Web Service Client classes,You can achieve this by following steps .
在 Eclipse Kepler 中生成 Web Service Client 类非常容易,您可以通过以下步骤来实现。
RightClick on any Project->Create New Other ->Web Services->Web Service Client->Then paste the wsdl url(or location) in Service Definition->Next->Finish
右键单击任何项目->新建其他->Web 服务->Web 服务客户端->然后将 wsdl url(或位置)粘贴到服务定义中->下一步->完成
You will see the generated classes are inside your src folder.
您将看到生成的类位于 src 文件夹中。
NOTE :Without eclipse also you can generate client classes from wsdl file by using wsimport command utility which ships with JDK.
注意:如果没有 Eclipse,您也可以使用 JDK 附带的 wsimport 命令实用程序从 wsdl 文件生成客户端类。
refer this link Create Web service client using wsdl
请参阅此链接使用 wsdl 创建 Web 服务客户端
回答by Captain Giraffe
The Eclipse team with The Open University have prepared the following document, which includes creating proxy classes with tests. It might be what you are looking for.
The Open University 的 Eclipse 团队准备了以下文档,其中包括使用测试创建代理类。这可能是您正在寻找的。
http://www.eclipse.org/webtools/community/education/web/t320/Generating_a_client_from_WSDL.pdf
http://www.eclipse.org/webtools/community/education/web/t320/Generating_a_client_from_WSDL.pdf
Everything is included in the Dynamic Web Projecttemplate.
一切都包含在动态 Web 项目模板中。
In the project create a Web Service Client. This starts a wizard that has you point out a wsdl url and creates the client with tests for you.
在项目中创建一个Web Service Client。这将启动一个向导,让您指出 wsdl url 并为您创建带有测试的客户端。
The user guide (targeted at indigo though) for this task is found at http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jst.ws.cxf.doc.user%2Ftasks%2Fcreate_client.html.
可在http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jst.ws.cxf.doc.user%2Ftasks%找到此任务的用户指南(不过针对 indigo)2Fcreate_client.html。
回答by nyxz
I wouldn't suggest using the Eclipse tool to generate the WS Client because I had bad experience with it:
我不建议使用 Eclipse 工具来生成 WS 客户端,因为我对它的体验很差:
I am not really sure if this matters but I had to consume a WS written in .NET. When I used the Eclipse's "New Web Service Client" tool it generated the Java classes using Axis (version 1.x)which as you can check is old (last version from 2006). There is a newer versionthough that is has some major changes but Eclipse doesn't use it.
我不确定这是否重要,但我不得不使用用 .NET 编写的 WS。当我使用 Eclipse 的“新 Web 服务客户端”工具时,它使用Axis(版本 1.x)生成了 Java 类,您可以检查它是旧的(2006 年的最新版本)。有一个较新的版本,虽然它有一些重大变化,但 Eclipse 不使用它。
Why the old version of Axis matters you'll say? Because when using OpenJDK you can run into some problems like missing cryptography algorithmsin OpenJDK that are presented in the Oracle's JDK and some libraries like this one depend on them.
你会说为什么旧版本的 Axis 很重要?因为在使用 OpenJDK 时,您可能会遇到一些问题,例如在 Oracle 的 JDK 中提供的 OpenJDK 中缺少加密算法,而像这样的一些库依赖于它们。
So I just used the wsimporttool and ended my headaches.
所以我只是使用了wsimport工具并结束了我的头痛。
回答by Shell Scott
You need to do next in command line:
您需要在命令行中执行下一步:
wsimport -keep -s (name of folder where you want to store generated code) urlToWsdl
for example:
例如:
wsimport -keep -s C://NewFolder https://www.blablabla.com
wsimport -keep -s C://NewFolder https://www.blablabla.com
回答by ishandutta2007
Options are:
选项是:
- Wsimportfrom Oracle uses JAXB
- Axisfrom Apache
- CXFfrom Apache
- Axis2from Apache offers choice between ADB(default), Apache XmlBeans, or JiBXfor data-binding
- 来自 Oracle 的Wsimport使用JAXB
- 来自 Apache 的轴
- 来自 Apache 的CXF
- Apache 的Axis2提供了ADB(默认)、Apache XmlBeans或JiBX之间的选择,用于数据绑定
Read through the above links before taking a call
在接听电话之前通读以上链接
回答by Harsh
Using command prompt in windows you can use below command to get class files.
在 Windows 中使用命令提示符,您可以使用以下命令来获取类文件。
wsimport "complete file path of your .wsdl file"
example : wsimport C:\Users\schemas\com\myprofile\myprofile2019.wsdl
if you want to generate source code you should be using below commnad.
如果你想生成源代码,你应该使用下面的 commnad。
wsimport -keep -s src "complete file path of your .wsdl file"
example : wsimport -keep -s src C:\Users\schemas\com\myprofile\myprofile2019.wsdl
Note: Here "-s" means source directory and "src" is name of folder that should be created before executing this command. Wsimport is a tool which is bundled along with JAVA SE, no seperate download is required.
注意:这里“-s”表示源目录,“src”是在执行此命令之前应创建的文件夹名称。Wsimport 是与 JAVA SE 捆绑的工具,不需要单独下载。