50

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?

I use Eclipse JEE Kepler. Maybe there are some plugins to do this automatically?

SOLO
  • 868
  • 9
  • 19
khris
  • 4,809
  • 21
  • 64
  • 94

6 Answers6

62

In Eclipse Kepler it is very easy to generate Web Service Client classes,You can achieve this by following steps .

RightClick on any Project->Create New Other ->Web Services->Web Service Client->Then paste the wsdl url(or location) in Service Definition->Next->Finish

You will see the generated classes are inside your src folder.

NOTE :Without eclipse also you can generate client classes from wsdl file by using wsimport command utility which ships with JDK.

refer this link Create Web service client using wsdl

Ashok_Pradhan
  • 1,159
  • 11
  • 13
  • I have two dynamic web projects in eclipse and I can only select the "other" project when running this wizard. They both seem to have the same setup. Servlet 2.5 etc. Any clues? – Tommy Nov 18 '14 at 19:35
  • @Ashok I have the same question and I am using Eclipse Indigo I did right click on one of my projects there is a new-> other but there is no Web Services option after that, would you please help me figure it out? – Mahsa Aug 10 '16 at 13:31
  • I can't browse to a WSDL on disk on the `Select Service Implementation` screen? – PeterX Sep 06 '17 at 04:15
29

Run this in your 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
mfluehr
  • 2,832
  • 2
  • 23
  • 31
Shell Scott
  • 1,679
  • 18
  • 28
9

I wouldn't suggest using the Eclipse tool to generate the WS Client because I had bad experience with it:

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 version though that is has some major changes but Eclipse doesn't use it.

Why the old version of Axis matters you'll say? Because when using OpenJDK you can run into some problems like missing cryptography algorithms in OpenJDK that are presented in the Oracle's JDK and some libraries like this one depend on them.

So I just used the wsimport tool and ended my headaches.

nyxz
  • 6,918
  • 9
  • 54
  • 67
9

Options are:

Read through the above links before taking a call

Community
  • 1
  • 1
ishandutta2007
  • 16,676
  • 16
  • 93
  • 129
3

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.

http://www.eclipse.org/webtools/community/education/web/t320/Generating_a_client_from_WSDL.pdf

Everything is included in the Dynamic Web Project template.

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.

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.

Captain Giraffe
  • 14,407
  • 6
  • 39
  • 67
  • Open university pdf file is simply step by step instruction. It wont give you any explenation about used options and configurations. – whd Jan 24 '17 at 09:09
3

Using command prompt in windows you can use below command to get class files.

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.

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.

Harsh
  • 2,893
  • 29
  • 16
  • I get below exception when I tried wsimport: [ERROR] A class/interface with the same name "com.sforce.soap.partner.DescribeGlobalTheme" is already in use. Use a class customization to resolve this conflict. line 2781 of file:/C:/temp/SC_Partner.wsdl – Quest_sfdc Apr 06 '22 at 07:00