VMware {code} Community
shankarvn
Contributor
Contributor
Jump to solution

How to add a library dependency to the java service modules?

Hi,

I am trying to add Google gson jar as a dependency to the chassis sample (/chassisRackVSphere-service) and I am running into some issues with the osgi setup.

////////////////////////////////////////////////////////////////////////////////////////

Resolver report:

        An Import-Package could not be resolved. Resolver error data <Import-Package: com.google.gson; version="0.0.0">. Caused by missing constraint in bundle <com.vmware.samples.chassisrackvsphereservice_1.0.0>

             constraint: <Import-Package: com.google.gson; version="0.0.0">

  at org.eclipse.virgo.kernel.install.pipeline.stage.resolve.internal.QuasiResolveStage.process(QuasiResolveStage.java:46)

  at org.eclipse.virgo.kernel.install.pipeline.internal.StandardPipeline.doProcessGraph(StandardPipeline.java:62)

  at org.eclipse.virgo.kernel.install.pipeline.internal.CompensatingPipeline.doProcessGraph(CompensatingPipeline.java:73)

  at org.eclipse.virgo.kernel.install.pipeline.stage.AbstractPipelineStage.process(AbstractPipelineStage.java:41)

  at org.eclipse.virgo.kernel.install.pipeline.internal.StandardPipeline.doProcessGraph(StandardPipeline.java:62)

  at org.eclipse.virgo.kernel.install.pipeline.stage.AbstractPipelineStage.process(AbstractPipelineStage.java:41)

  at org.eclipse.virgo.kernel.deployer.core.internal.PipelinedApplicationDeployer.driveInstallPipeline(PipelinedApplicationDeployer.java:359)

////////////////////////////////////////////////////////////////////////////////////////

Here are the things that I did in service of adding the  gson-2.2.4.jar to the list of libraries (that I will be using from my service module).

1. Added gson-2.2.4.jar to chassisRackVSphere-service\lib

2. Added gson-2.2.4.jar to the list of referenced libraries in STS.

3. Fixed the ANT build file to add this jar to the classpath

<target name="compile-java" depends="clean" description="Do not select this internal target.">

      <javac includeantruntime="false" destdir="${CLASSES}" fork="true" debug="on">

         <src path="${basedir}/src/main/java"/>

         <!-- <src path="${basedir}/src/test/java"/> for future test files -->

         <classpath>

            <!-- remove this if you are not using the SDK on the java side -->

            <pathelement path="${VSPHERE_SDK_HOME}/libs/vsphere-client-lib.jar"/>

          <pathelement path="lib/commons-logging-1.1.1.jar"/>

          <pathelement path="lib/gson-2.2.4.jar"/>

         </classpath>

      </javac>

   </target>

4. Fixed the manifest file to include the gson package

/////////////////////////////////////////////////////////////////////////////////////////

Import-Package: org.apache.commons.logging,

com.google.gson,

com.vmware.vise.data,

com.vmware.vise.data.query,

com.vmware.vise.data.uri,

com.vmware.vise.vim.data

/////////////////////////////////////////////////////////////////////////////////////////

I am not sure what I am missing. How do I add third party libraries to the service module (in this case chassisRackVSphere-service)? Any help is appreciated.

Thank you

Shankar

Reply
0 Kudos
1 Solution

Accepted Solutions
laurentsd
VMware Employee
VMware Employee
Jump to solution

You forgot one step described in the FAQ "How to use 3rd party java libraries?", i.e. make your gson library available on the server.  Here is an extract of this FAQ:

Libraries packaged as OSGI bundles should be in a location known to the server:

  • In development mode you can copy them in server/repository/usr, one of the default directories for loading libraries (you need to restart the server).
  • If the server is already running you can also copy them in server/pickup because the bundles will be hot-deployed (i.e. no need to restart, but this forces you to deploy your plugin after the library, see Note 2. below).
  • Finally, you can keep them at their current location and add a path in server/configuration/com.springsource.repository.properties.
  • In production mode your plugin is installed as a plugin package, it is neither practical nor recommended to add libraries to server/pickup or server/repository/usr on your production server. Instead you should include them in your package's plugins directory along with your .war and .jar bundles. You also need to list the libraries's Bundle-SymbolicName in plugin-package.xml.

View solution in original post

Reply
0 Kudos
3 Replies
laurentsd
VMware Employee
VMware Employee
Jump to solution

You forgot one step described in the FAQ "How to use 3rd party java libraries?", i.e. make your gson library available on the server.  Here is an extract of this FAQ:

Libraries packaged as OSGI bundles should be in a location known to the server:

  • In development mode you can copy them in server/repository/usr, one of the default directories for loading libraries (you need to restart the server).
  • If the server is already running you can also copy them in server/pickup because the bundles will be hot-deployed (i.e. no need to restart, but this forces you to deploy your plugin after the library, see Note 2. below).
  • Finally, you can keep them at their current location and add a path in server/configuration/com.springsource.repository.properties.
  • In production mode your plugin is installed as a plugin package, it is neither practical nor recommended to add libraries to server/pickup or server/repository/usr on your production server. Instead you should include them in your package's plugins directory along with your .war and .jar bundles. You also need to list the libraries's Bundle-SymbolicName in plugin-package.xml.

Reply
0 Kudos
shankarvn
Contributor
Contributor
Jump to solution

Hi laurentsd,

Thank you very much. That worked!

Regards

Shankar

Reply
0 Kudos
tcng889
Contributor
Contributor
Jump to solution

laurentsd

  We need add third party libraries such as commons-codec-1.6.jar, dom4j-1.6.1.jar, lombok-1.16.4.jar into the project. I only have the generic jars.

  And desperately looking for libraries packaged as OSGI bundles. Searched online and got  org.apache.servicemix.bundles.dom4j-1.6.1_5 and following instruction adding to the project,

but when deploying it still complains Resolver error data. Where can we find the Virgo resolvable bundles except those already under server/repository/usr

2016-07-02T12:10:02.001-07:00] [ERROR]  TCP Connection(2)-127.0.0.1  <DE0002E> Installation of bundle 'com.mycompany.myPlugin.MyPlugin' version '1.0.0' failed. org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyBundleDependenciesException: Unable to satisfy dependencies of bundle 'com.mycompany.myPlugin.MyPlugin' at version '1.0.0': Cannot resolve: com.mycompany.myPlugin.MyPlugin

    Resolver report:

        An Import-Package could not be resolved. Resolver error data <Import-Package: com.mycompany.myService; version="0.0.0">. Caused by missing constraint in bundle <com.mycompany.myPlugin.MyPlugin_1.0.0>

             constraint: <Import-Package: com.mycompany.myService; version="0.0.0">

at org.eclipse.virgo.kernel.install.pipeline.stage.resolve.internal.QuasiResolveStage.process(QuasiResolveStage.java:46)

  at org.eclipse.virgo.kernel.install.pipeline.internal.StandardPipeline.doProcessGraph(StandardPipeline.java:62)

Reply
0 Kudos