I was following this tutorial to embed OSGi in my maven based application. I have one class file that creates and start the framework as mentioned here and it works fine there as I am able to get BundleContext easily.
I have added this dependency in my pom.xml file.
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-mvn</artifactId>
<version>1.3.6</version>
</dependency>
Now when I am running my whole framework and when it reaches to one of my new class file in the same maven based project where I need to use BundleContext so I thought I can use this piece of code to get the BundleContext`
FrameworkUtil.getBundle(ModelProcessor.class).getBundleContext();
but somehow the above code throws me NullPointerException and then I tried printing out to see what's happening-
System.out.println(FrameworkUtil.getBundle(ModelProcessor.class));
So the above lines prints- null
Does anyone have any idea what does null means here in terms of OSGi and what I can do to resolve this issue?
Thanks for the help.