I am trying to connect to SharePoint from my Java code. Below is the code I am using,

 NtlmAuthenticator credentials = new NtlmAuthenticator("DOMAIN", "username", "password");
 // Initialize proxy settings
 HttpProxy httpProxy = new HttpProxy("myProxyServer.com", 8888);
 // Connect to Sharepoint
 SPSite instance = new SPSite(new URL("https://www.server.com/"), credentials, httpProxy, true, SPVersion.SP2013);
// Get root web instance
 SPWeb rootWeb = instance.getRootWeb();
 // Get list of all lists and document libraries from root web
  List<SPList> lists = rootWeb.getLists();

However I am not able to connect. Also i am not getting what to pass for the proxy field.

Can you please help me?

2 Answers 2


I see you use the java-sharepoint-library: https://code.google.com/p/java-sharepoint-library/

if you check the source you'll see there are several constructors for a SPSite:


make sure which one you need. If you don't have a proxy simply do

HttpProxy httpProxy = null;

and if you do have one, ask your admin for it.

you actually do everything right. Make sure you have the right domain, credentials and url to your SP site.


You can to use the following approach:

import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class SimpleAuthenticator extends Authenticator {

  private final String username;
  private final char[] password;

  public SimpleAuthenticator(final String username, final String password) {
    this.username = new String(username);
    this.password = password.toCharArray();


public PasswordAuthentication getPasswordAuthentication() {
    return (new PasswordAuthentication (username, password));

//Use class in main //

SimpleAuthenticator authenticator = new SimpleAuthenticator(username, password);

public class SPClient {

  private static String username = "your sharepoint username";
  private static String password = "your sharepoinnt password";
  private static String BasesharepointUrl = "https://mysharepoint.com/Book Names";
  private static ListsSoap listsoapstub;
  private static VersionsSoap versionssoapstub;
  private static CopySoap copysoapstub;

  private static SharePointClient getInstance(){
      return(new SharePointClient());
  public static void main(String[] args) {
      try {

          NtlmAuthenticator authenticator = new NtlmAuthenticator(username, password);

          //Authenticating and Opening the SOAP port of the Copy Web Service
          listsoapstub = SharePointClient.getSPListSoapStub(username, password, BasesharepointUrl);

          // Displays the lists items in the console

      } catch (Exception ex) {

Original Post: http://blog.ashwani.co.in/blog/2013-07-28/connect-and-access-sharepoint-webservice-from-java/


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.