user793735
user793735

Reputation: 11

Bundle dependency could not be resolved due to missing constraint on import package, How to add jar dependency in a an osgi bundle using maven?

I am new to maven.

I am trying to import a jar dependency (com.jcraft.jsch) in my opendaylight controller project. The code compiles successfully. But when the controller is run, it throws the following errors.


!ENTRY org.opendaylight.controller.samples.ssr 4 0 2013-10-11 10:25:14.624 !MESSAGE FrameworkEvent ERROR !STACK 0 org.osgi.framework.BundleException: The bundle "org.opendaylight.controller.samples.ssr_0.4.0.SNAPSHOT [36]" could not be resolved. Reason: Missing Constraint: Import-Package: com.jcraft.jsch; version="0.0.0" at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332) at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323) at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390) at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544) at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457) at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243) at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438) at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340) 2013-10-11 10:25:14.627 IST [org.opendaylight.controller.logging.bridge.internal.LogListenerImpl@190c63b2] ERROR o.o.c.logging.bridge.OSGI2SLF4J - Bundle:org.opendaylight.controller.samples.ssr Message:FrameworkEvent ERROR Exception:org.osgi.framework.BundleException: The bundle "org.opendaylight.controller.samples.ssr_0.4.0.SNAPSHOT [36]" could not be resolved. Reason: Missing Constraint: Import-Package: com.jcraft.jsch; version="0.0.0"


I have imported that package. The package org.opendaylight.controller.samples.ssr is added by me in it. Basically, I have modified one of the packages in samples. The problem is I am trying to import one jar dependency com.jcraft.jsch in one of the classes in this package. But there is a problem with importing this jar.

I have been slogging after this issue for last couple of weeks. Any suggestions or solutions please. Thanks in advance.

Upvotes: 1

Views: 6185

Answers (1)

sharmadhrv
sharmadhrv

Reputation: 11

I was facing the same issue in OpenDaylight. Here's a solution that I figured out after some trial and error (Let me know if you find any step to be unnecessary):

The Maven dependency in your case would have, Group Id as com.jcraft, Artifact Id as jsch, Version as 0.1.31 (say) and Imported Package ias com.jcraft.jsch. Also, your OpenDaylight module is org.opendaylight.controller.samples.ssr.

In the file distribution/opendaylight/opendaylight-osgi-launcher.launch and distribution/opendaylight/opendaylight-osgi-launcher-local.launch, add your dependency and the module to the following tags:

...
<stringAttribute key="target_bundles" value="com.jcraft.jsch@default:default,ch.qos.logback.classic@default:default, ch.qos.logback.core@default:default ..."/>
.
.
<stringAttribute key="workspace_bundles" value="org.opendaylight.controller.samples.ssr@default:default,org.opendaylight.controller.arphandler@default:default, ..."/>
...

In file distribution/opendaylight/opendaylight.target, add a unit entry as,

...
<unit id="com.google.gson" version="2.1.0"/>
<unit id="com.jcraft.jsch" version="0.1.31"/>
...

In distribution/p2site/pom.xml, add the artifact entry as,

...
<artifact>
  <id>com.google.code.gson:gson:2.1</id>
  <transitive>false</transitive>
  <override>false</override>
</artifact>
<artifact>
  <id>com.jcraft:jsch:0.1.31</id>
  <transitive>false</transitive>
  <override>false</override>
</artifact>
...

In commons/opendaylight/pom.xml, add the dependency entry as,

...
<dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
  <version>2.1</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>com.jcraft</groupId>
  <artifactId>jsch</artifactId>
  <version>0.1.31</version>
</dependency>
...

Do a complete OpenDaylight maven build and run. It should work fine. In case, this dependency has further chained dependencies you might get the error again. Import those dependencies the same way.

Upvotes: 1

Related Questions