Get Started Tutorial

Steve Jin, Creator of VI Java API

1. Go to the VI Java API web site( http://vijava.sf.net ) and click on the download link at the top.

On the download page, select the latest release and click the download link as follows:

Choose the binary vijava2b120090221.zip (Note: the name can be different for future releases. Just pick up latest one) and start to download it. Optionally, you can download the package with source code -- vijava*src.jar.

2. Unzip the vijava2b120090221.zip file to a folder of your choice and you will get two jar files, one for VI Java API itself, and the other is dom4j-1.6.1.jar.

3. Start Eclipse. If you haven’t done so, you can go to http://www.eclipse.org to download and install it. It’s straightforward.

If you already use Eclipse, it’s most likely your workspace has projects already. That is totally fine. Note: JDK/JRE1.6 or higher is required. Please upgrade if not yet. 1.5 can be supported but need a little tweak.

4. Create a new Java project. In the wizard, enter “MyFirstVIJavaAPIProj” as the project name, and leave the rest as default. Click Finish button at the bottom.

Then you will see the project get created:

5. Configure the project to reference the two jars that were just unzipped:

a) Right click the project name and select the “Properties” (normally the last one in the context menu).

b) You will see a dialog box titled as “Properties for MyFirstVIJavaAPIProj.” Select “Java Build Path” from the left side, and “Libraries” tab on the right side.

c) Click “Add External JARs…” and select the two jars you just unzipped as follows:

6. Code your first Java program.

a) Create a new Java class by Right Click New Class.

b) Copy the sample code and paste into the HelloVM.java. Save it. http://vijava.svn.sourceforge.net/viewvc/vijava/trunk/src/com/vmware/vim25/mo/samples/HelloVM.java

7. Run your code.

a) Right click “HelloVM.java” and choose Run As Java Application. You will see error from the console. Oops… What is wrong?

b) Double click the HelloVM.java file and locate the following line:

ServiceInstance si = new ServiceInstance(new URL(https://8.8.8.8/sdk"), "root", "password", true);

Note: You must change it to your own environment. And don’t forget the SDK in your url string. The https works by default, and http works as well if you have changed server side configuration.

c) After you click the Run button, you will see print out from the Console View like the following:

 

Congratulations you got your first VI SDK program running in Java! Additional tutorial can be found at VMware community here by Pierre Lainé.

What is next:

1. Subscribe to the blog, and follow Steve at Twitter. The blog site has many in-depth introductions and discussions about the API. Optionally, you can buy the book VMware VI and vSphere SDK (Disclosure: it's written by Steve) for the most complete introduction of vSphere API and VI Java.

2. Try more samples shipped with VI Java API. Check them out from http://vijava.sf.net

3. Participate in the community forum. You can find the link to forum from project home.

4. Let me know how you like it and how we can make it better for you. You can leave message in the forum or feature request.