How to run Java samples from VMware SDK on Ubuntu 10.04

There are subtle differences in all Linux platforms and when I got to run VMware SDK Java samples on Ubuntu 10.04 I found there is something that is worth to share in addition to my first post about it.

First of all, there are very convenient “default” packages for JRE and JDK that have openjdk-6-jre and openjdk-6-jdk:

apt-get install default-jre defalt-jdk

Of course that means a different value for JAVAHOME:

export JAVAHOME=/usr/bin/openjdk-6/

Second, in my first post I did not describe how to get and store VMware server certificates.

If you follow the Setup Guild then you have to connect to a VMware server by SSH or use the vClient. But you can get the certificate from the Firefox browser: when connecting to a VMware server and asked to confirm the certificate, there is a button to export it. This allows to save the certificate locally and then add it to the keystore:

keytool -import -file XXX.XX.XX.XX.XX.cer -alias XXX.XX.XX.XX.XX \
-keystore vmware.keystore VMKEYSTORE=~/vmware-certs/vmware.keystore
export VMKEYSTORE

Also the tofrodos package has different name for the dos2unix utility, it is called fromdos now:

apt-get install tofrodos
cd %SDKHOME%\samples\Axis\java
fromdos *.sh

Unfortunately the axis binaries I still had to download manually.

How to Assign Task Description

In one of comments the following code did not set a task description (shown in vSphere Client in Details column):

LocalizableMessage lm = new LocalizableMessage(); 
lm.setMessage(“Hello World”); 
myTask.getTaskInfo().setDescription(lm);

The problem is in missing key property of the newly created LocalizableMessage: it must be assigned from the task itself.

This is how it’s supposed to be done (Java):

LocalizableMessage lm = new LocalizableMessage();
lm.setKey(myTask.getTaskInfo().getKey());
lm.setMessage(“Hello World”);
myTask.getTaskInfo().setDescription(lm);

This is an example in C# (taskInfo is known value of Vim.TaskInfo type):

LocalizableMessage myDetailMessage = new Vim25Api.LocalizableMessage()
   { key = taskInfo.key, message = "my details" };
connection.Service.SetTaskDescription(taskInfo.task, myDetailMessage);

How to run Java samples from VMware SDK

VMware SDK a.k.a. vSphere Web Services SDK 4.0 comes with Java and C# samples. This is what it took me to get them running on Ubuntu 8.10.

1. Download the SDK from vmware.com into a separate directory:

> mkdir vi-sdk-4.0.0-161137

2. Install Java and Axis:

> apt-get install sun-java5-bin sun-java5-demo sun-java5-doc \
sun-java5-fonts sun-java5-jdk sun-java5-jre sun-java5-plugin \
tofrodos
> wget http://apache.raffsoftware.com/ws/axis/1_4/axis-bin-1_4.tar.gz
> tar xzf axis-bin-1_4.tar.gz
> ln -s /home/dmitri/projects/vi-sdk-4.0.0-161137/SDK/ visdk

3. Setup environment variables:

export AXISHOME=~/apps/apache/axis/
export JAVAHOME=~/apps/java/jdk1.5.0_19/
export SDKHOME=~/apps/visdk/
export WBEMHOME=${SDKHOME}samples/Axis/java/lib/wbem.jar
PATH=${PATH}:${AXISHOME}/bin:${JAVAHOME}\bin
export PATH
CLASSPATH=${CLASSPATH}:${AXISHOME}lib/axis.jar:\
${AXISHOME}lib/axis-ant.jar:\
${AXISHOME}lib/commons-discovery-0.2.jar:\
${AXISHOME}lib/commons-logging-1.0.4.jar:\
${AXISHOME}lib/jaxrpc.jar:${AXISHOME}lib/log4j-1.2.8.jar:\
${AXISHOME}lib/saaj.jar:${AXISHOME}lib/wsdl4j-1.5.1.jar:\
${JAVAHOME}lib/tools.jar:${SDKHOME}samples/Axis/java/vim.jar:\
${SDKHOME}samples/Axis/java/vim25.jar:\
${SDKHOME}samples/Axis/java/apputils.jar:\
${SDKHOME}samples/Axis/java/samples.jar:\
${SDKHOME}samples/Axis/java/lib/activation.jar:\
${SDKHOME}samples/Axis/java/lib/mailapi.jar:\
${SDKHOME}samples/Axis/java/lib/wbem.jar
export CLASSPATH

4. Build the samples following the Setup Guide

> cd %SDKHOME%\samples\Axis\java
> ./build.sh

5. Run the samples:

>./run.sh com.vmware.samples.general.SimpleClient --url https://123.45.67.89/sdk \
--username admin --password password

6. Pat yourself on the back.