Thursday, March 7, 2013

Generating a WSDL from Salesforce and then generating Java libraries (JAR)....

The first thing you have to do is make sure your Java (JDK) development environment is all set up.  I have a short guide to doing this here: http://anotherforceblog.blogspot.com/2013/03/setting-up-jdk-se616-and-eclipse-for.html

Once you are all good to go and can at the very lest, type java at the command prompt without getting an error follow these general steps:

The First thing you will need to go do is to get the Force.com Web Service Connector (WSC).  You can find it here:

http://code.google.com/p/sfdc-wsc/downloads/list

I will be using wc-23.jar for this.

Save this file into your "lib" folder, ie:

C:\Program Files (x86)\Java\jdk1.6.0_43\lib

First things first.  I have had issues downloading WSDL's using Chrome.  FireFox and IE both seem to get them correctly.  I'll go through the steps using Firefox as any little thing seemed to throw errors for me while building the libraries.

First log into Salesforce and then goto "Your Name" > Setup > Develop > API

Select the WSDL you want to generate by clicking on the link under the WSDL type, I am generating an Enterprise WSDL for this.

The next screen will list all of the packages installed in your org, you can review the verson settings for each if there are any.

When you are ready, click the "Generate" button.

You'll be redirected to wsdl.jsp page which is an XML document.

Now Save this, in Firefox : Save Page As > Now Firefox is going to have a name already populated in the save field, delete it and name it on your own.  If you save it or rename it with the.wsdl extension FF put on it, it will save as a .wsdl.xml file and will cause the wsc program to fail (no such file found etc..)

Select your save location and click save

Once your file has been saved open up a CMD prompt and navigate to the folder that has your .wsdl file in it.  The easiest way to do this is to navigate to the location in explorer and then copy the address out of the address bar and then go into your cmd window, type CD <space> and then right click and select paste and hit enter



Now that you are in the directory, you will need to run the following (similar different version/type) command to generate the library.jar:

java -classpath "C:\Program Files (x86)\Java\jdk1.6.0_43\lib\wc-23.jar;C:\Program Files (x86)\Java\jdk1.6.0_43\lib\tools.jar" com.sforce.ws.tools.wsdlc enterprise.jar entlib.jar

The breakdown for this is: java -classpath "<directory with wsc-2*.jar>;<directory with jdk tools.jar>" com.sforce.ws.tools.wsdlc <wsdl filename> <jar output name>



If everything was in the right place and all the files were correct you should have a new jar file named whatever you named it in the directory with your WSDL file.




1 comment:

  1. I'll probably go and clean this post up a lot, later. It was done fast and dirty since I am at work!

    ReplyDelete