title: Force Imports in Apache Karaf
body: <p>I have bundle that deals mostly with interfaces and it uses a factory from a thrid party jar to get the instances for the interfaces it is using.
  For example,</p>
  
  <blockquote>
    <p>my-bundle.jar has...</p>
  </blockquote>
  
  <pre><code>com.oth.itf.Intrface itf = Fctry.getInstance('ABC');
  </code></pre>
  
  <p>has the </p>
  
  <pre><code>imports-package for com.oth.itf
  </code></pre>
  
  <blockquote>
    <p>third-party.jar has..</p>
  </blockquote>
  
  <pre><code>public static com.oth.itf.Intrface getInstance(String abc) {
     if (...) {
         return new com.oth.impl.ItfInstance();
     }
  }
  </code></pre>
  
  <p>has the <code>exports-package for com.oth.itf and com.oth.impl</code></p>
  
  <p>Everything works fine and bundles also get deployed but the issue is that I am getting </p>
  
  <blockquote>
    <p>ClassNotFoundException for ItfInstance </p>
  </blockquote>
  
  <p>on </p>
  
  <blockquote>
    <p>my-bundle</p>
  </blockquote>
  
  <p>when the code gets executed. </p>
  
  <p>I tried adding import-package for com.oth.impl but to no avail. Things started to work when I added a</p>
  
  <blockquote>
    <p>dummy declaration of com.oth.impl.ItfInstance</p>
  </blockquote>
  
  <p>some where in my-bundle.jar. Looks like, Karaf gets the imports only if we explicitly use them. Is there a better way? Is there a way to force Karaf to import packages even if we don't use them explicitly?</p>