This simple client application accepts command-line arguments for the vSphere server name (DNS name or IP address), user name, and password.

To build a simple vSphere client application in Java, use the following steps.

Procedure

  1. Import the vSphere Web Services API libraries:
    import com.vmware.vim25.*;
  2. Import the necessary Java (and JAX-WS connection, bindings, and SOAP) libraries:
    import java.util.*;
    import javax.net.ssl.HostnameVerifier;
    import javax.net.ssl.HttpsURLConnection;
    import javax.net.ssl.SSLSession;
    import javax.xml.ws.BindingProvider;
    import javax.xml.ws.soap.SOAPFaultException;
  3. Create the TestClient class:
    public class TestClient {
  4. Include the class variable declarations/definitions. Use a TrustManager class to accept all certificates, as shown in Accessing the vSphere Web Services HTTP Endpoint with JAX-WS . This is not appropriate for a production environment. Production code should implement certificate support.
  5. Use the vSphere Web Services APIs to create the connection, as shown in Accessing the vSphere Server from a Web Services Client.
  6. Retrieve data from the vSphere or vCenter Server. In this example, we are just going to print out the product name, server type, and product version to prove that the client is connected and working correctly.
    System.out.println(serviceContent.getAbout().getFullName());
    System.out.println("Server type is " + serviceContent.getAbout().getApiType());
    System.out.println("API version is " + serviceContent.getAbout().getVersion());
  7. Use the VimPort object to close the connection, as shown in Closing the Connection from a Web Services Client. Always close your server connections to maintain security.