VMware {code} Community
annahernandez99
Contributor
Contributor

vsphere api : failed to create ServiceInstance using vijava vsphere API

I am new to vsphere API and trying to follow samples here.

I have added following jars in my classpath:

1.yavijava-6.0.05.jar and dependent jars

2.vSphere Client SDK jars (vsphere-client-sdk-7.0.0.10100-15863815\html-client-sdk\libs)

when I try to create serviceInstance object,

ServiceInstance si = new ServiceInstance(new URL("https://<VC ip>/sdk/vimService"), "<username>", "<password>",
true);
I get following error:

Exception in thread "main" java.lang.NoSuchMethodError: 'void com.vmware.vim25.ManagedObjectReference.set_value(java.lang.String)' at com.vmware.vim25.mo.ServiceInstance.(ServiceInstance.java:58)

Earlier I tried using vijava jars and I got following error

java.lang.RuntimeException: java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException: null Nested exception: null

https://exonlinecalculator.com/

Reply
0 Kudos
6 Replies
scott28tt
VMware Employee
VMware Employee

@annahernandez99 

Moderator: Moved to vSphere Client SDK Discussions


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
_vladi_
VMware Employee
VMware Employee

Hi @annahernandez99,

If you are trying to get up to speed with building UI plugins please use the vSphere Client SDK and especially the Remote plugin development guide.

If you are more interested in the core vCenter API please use the vSphere Web Services SDK.

In terms of the actual library to use VMware supports only vim25.jar (official vSphere Web Service SDK deliverable). You can find one in the vSphere Client SDK jars (html-client-sdk\libs).

javijava.jar and vijava.jar are actually 3rd party libraries packaging the same APIs but not released by VMware. As such their backward compatibility with new versions of vSphere does not come out of the box.

Also keep in mind you should use only one of these libraries at a time as they might clash runtime.

Obviously, my recommendation is to use only vim25.jar.

Hope this helps.

Cheers,

Vladi

Reply
0 Kudos
doskiran
Enthusiast
Enthusiast

With yavijava-6.0.05.jar we can still connect to VC7.0 +,

Try this code,

ServiceInstance si = new ServiceInstance(new URL("https://" + vcIPaddress + ":443/sdk"), userName, passwd,
true);

System.out.println(si.getAboutInfo().getFullName()); // VMware vCenter Server 7.0.2 build-17694817

Also set below two VM arguments ,i.e,

-Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
-DUSESSL=true

My jars:

---------

doskiran_0-1621959513897.png

 

 

 

 

 

 

Reply
0 Kudos
SebEnn
Contributor
Contributor

The error occurs, because vijava and your chosen fork yavijava are trying this:

SERVICE_INSTANCE_MOR.set_value("ServiceInstance");

The problem is the following:

That code tries to use the method ManagedObjectReference.set_value(String) and the jar comes with that class included.
If you added the default vim25.jar from VMware it also includes this class with the exact same name and package path.
Now some part has to decide which of these two classes its gonna use when that method gets called, but they're not identical. The vim25-version instead of set_value(String) has the method setValue(String). So if whatever part decides to use the vim25-version, the method set_value(String) is not existing and throws your error.

So in short: make sure that you dont use vijava/yavijava and vim25 in the same project.

Reply
0 Kudos
girishbapt
Contributor
Contributor

Hi,

I want to know where is latest java APIs with 7.0.2 version of APIs, to work with Remote Plug-ins with the vSphere Client SDK (7.0 Update 2). I am not able find java samples or API documentation/ javadocs

We can see java script APIs but not java APIs. Am I missing something?

Regards,

Girish

Reply
0 Kudos
_vladi_
VMware Employee
VMware Employee

Hi Girish,

Remote plugins are serving the UI resources directly from the vendor backend appliance. 

If it runs Java you can use the vSphere Web Services SDK 7.0.2 (vim25) which is available here: https://code.vmware.com/web/sdk/7.0/vsphere-management

Note these are backend APIs, hence you don't see this in the Remote plugins guide which is covering vSphere Client SDK.

That said, the vSphere Client SDK contains a remote-plugin-sample which demonstrates the usage of vim25 Java APIs.

Please check that for code references.

Cheers,

Vladi 

Reply
0 Kudos