Packaging and Exposing the Service
Last Updated December 16, 2024

To make your Java service available for use with the
vSphere Web Client
and the
vSphere Client
, you must export the service and add it to the Spring configuration on the application server. Spring uses the OSGi model to share Java libraries.

Exporting the Service

You must locate the
/src/main/resources/META-INF/MANIFEST.MF
file in your service JAR bundle and ensure that the Java service package is exported. To export the package, the following line must appear in the
MANIFEST.MF
file:
Export-Package: com.vmware.myService
In the example line,
com.vmware.myService
is the name of the service package you created.

Adding the Service to the Spring Configuration

You add your service to the Spring configuration on the application server by creating a
<bean>
element in the Spring configuration file. In the JAR bundle, locate the
/src/main/resources/META-INF/spring/bundle-context.xml
file. The file contains a
<beans>
XML element containing services in the configuration. Add your service as a new
<bean>
as shown in the following example.
<bean name="myServiceImpl" class="com.vmware.myService.MyServiceImpl"/>
The name attribute is the name of your service implementation, and the class attribute contains the class you created that implements the service interface.
You must also expose the service interface as an OSGi bundle in the Spring framework. In the JAR bundle, locate the
/src/main/resources/META-INF/spring/bundle-context-osgi.xml
file. This file also contains a
<beans>
XML element. Add your service by using the following line.
<osgi:service id="myService" ref="myServiceImpl" interface="com.vmware.myService.MyService"/>
The
id
attribute is the name of your service, the
ref
element specifies the service implementation you added to the
bundle-context.xml
file, and the
interface
element contains the class that defines the service interface.