Salesforce Development with Java: Generating Java Stub Files

I’m wondering if there aren’t many people in the world like me, who sometimes solve Salesforce problems using Java console apps, but aren’t really “Java developers.” I’ve used Java for such things over the past few years because I can use it without expensive IDE licenses (in other words, I don’t have to buy a full license of Visual Studio or fight with lesser tools using C#). Java is enough like Apex that I’m comfortable enough with it, and there’s lots that can be Googled to get value out of the Salesforce SOAP, metadata, and tooling APIs using Java. That said, every so often, I find myself at a new job, or needing to upgrade, and I have a HORRIBLE time figuring out how to generate Java stub files from the Salesforce WSDLs and the Salesforce Web Services Connector (WSC). I’m going to try to write up what I just did this time around so 1) I’ll have the steps for myself the next time I find myself trying to figure this out, and 2) hopefully someone else in the world will get some use out of this. Here goes…

  1. Go straight to Maven Repository for the “Force WSC” project and pick up the latest uber binary for the WSC.
    • PLEASE NOTE: Make sure you get the uber binary. To do that:
      1. Click the API number in the “Version” column, which is a link. You’ll probably want the one at the top, which should be the most current API version available.
      2. On the revealed page, look for the “Files” row in the table toward the top, and click “View All.”
      3. In the long list of files, find the one with a name like: force-wsc-51.0.0-uber.jar
        • The numbers in the filename will reflect the API version of the binary selected above.
  2. Put that jar, and the WSDL file you generated from Salesforce (if you need help with that, just Google it; lots of people have written up how to generate the WSDL), into the same directory.
  3. Open that directory in a command line tool (I use Git Bash or PowerShell, but use what you’re comfortable with).
  4. Run the WSC jar / build your stub file.
    • You’re going to see lots of syntax for this all over the Internet. You’ll see blogs referencing a need to have various dependencies downloaded and included in your classpath when you try to run the jar (StringTemplate, Rhino, etc.). I think the developers making the WSC are, these days, including everything you need in the “uber” WSC jar. So, try this syntax (update the API version and file names):
java -classpath .\force-wsc-51.0.0-uber.jar com.sforce.ws.tools.wsdlc .\wsdl.jsp.xml .\partner.jar

That worked for me. I’m hoping this helps other Salesforce developers with “beginner-to-intermediate” Java skills like me to figure this out.

Screenshot 1: The Maven Repository view where you click the API number link…
Screenshot 2: The Maven Respository view where you click “View All” in the “Files” row to find the “uber” jar…
Screenshot 3: The list of downloadable binaries…