java.lang.NoClassDefFoundError: com.sforce.soap.enterprise.Connector

Finally I got solution for my problem.

It was a matter of executing command with multiple libraries as in this link.

Along with force-wsc-29.0.0.jar from here, download rhino js-1.7R2.jar from here and string template ST-4.0.7.jar file from here.

Navigate to where these files are placed.

Then, run following command

$ java -classpath force-wsc-29.0.0.jar:js-1.7R2.jar:ST-4.0.7.jar com.sforce.ws.tools.wsdlc enterprise.wsdl enterprise.jar

Resulting enterprise.jar file will be generated in current working directory.

That's it!.

Thanks to Abhinav Gupta and Andrew Fawcett for their continuous support.


What is your classpath, is it just libs folder or all jars in the lib folder. I think you need to add both wsc and enterprise jar files to the classpath explicitly.

Edit I realised after checking new github repo for WSC, that it moved to v30 from v23.0, that should hardly make a difference to problem. But as its always good to use latest stable lib, I gave a shot with github repo for WSC and things were working for me. Link to new repo : https://github.com/forcedotcom/wsc

Here are the steps you need(adding here, as some steps are not correct on repo README, I have to differ from them to make it work):

1) Clone repo :

$ git clone https://github.com/forcedotcom/wsc.git

2) MVN build

$ mvn clean package

3) Generate enterprise jar for your wsdl using following command, please replace paths as needed

$ java -classpath target/force-wsc-30.0.0-uber.jar com.sforce.ws.tools.wsdlc ~/Desktop/enterprise.wsdl enterprise.jar

4) Create a Java project, add WSC jar(force-wsc-30.0.0-uber.jar) and enterprise.jar to buidpath/classpath. Try running following code, it should be compilable:

import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.sobject.Contact;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;

public class EntTest {

    public static void main(String[] args) throws ConnectionException {
        ConnectorConfig config = new ConnectorConfig();
        config.setUsername("username");
        config.setPassword("password");

        EnterpriseConnection connection = Connector.newConnection(config);

        // query for the 5 newest contacts      
        com.sforce.soap.enterprise.QueryResult queryResults = connection.query("SELECT Id, FirstName, LastName, Account.Name " +
                "FROM Contact WHERE AccountId != NULL ORDER BY CreatedDate DESC LIMIT 5");

        if (queryResults.getSize() > 0) {
            for (int i=0;i<queryResults.getRecords().length;i++) {
                // cast the SObject to a strongly-typed Contact
                Contact c = (Contact)queryResults.getRecords()[i];
                System.out.println(" ------------- Id: " + c.getId() + " - Name: "+c.getFirstName()+" "+
                        c.getLastName()+" - Account: "+c.getAccount().getName());
            }
        }
    }
}

Let me know if you run into any more issues.