Category Archives: apache-felix

Apache Felix File Install example in karaf

Is there any example of how to configure/install Apache Felix File? On the official website, it mentions that you need to configure properties, etc. But nowhere have they mentioned where you need to put those configuration properties - how to set it up, etc.

I have deployed a org.apache.felix.fileinstall-3.5.0.jar file in karaf and I have the felix framework installed. Now I don't know where should I put those configuration properties so that the file install will read it.

Can anyone guide me on this?

How to AOP aspectj in OSGi with Apache Felix

I'm currently working on an OSGi project. Without many experiences in AOP combined with OSGi, I would like to know how to best do AOP in an OSGi environment? We have implemented the AOP scenario to create a console that intercept the call to a bundle in order to store the elapsed time for each task started by this bundle. Today, this aspect has been deployed on a jboss container using the LoadTimeWeaver provided by aspectj (adding an agent to the jboss start script in order to instrument the jars in the container -javaagent:%APP_HOME%\application\lib\aspectjweaver-1.6.11.jar). I've read some articles about this problem, but did not find a solution that suits well for me. There is, for example, an Equinox Incubator project for AspectJ. But since I'm using Apache Felix and Bnd(tools) I want to avoid using something from Equinox. One requirement for the weaving process will be that it should be at load-time as well (a bundle for aspectj that instrument the method inside another bundle). Someone can share experiences with such a use case using AOP aspectj with OSGI Felix ?

Apache Felix File Install jar from deploy folder

I am trying to use Apache Felix File Install with an embedded version of Felix. The basic idea is simple, I have a jar application file that can be launched using standard java -jar app.jar and the application will startup Apache Felix framework and then look in a hot deploy folder installing, updating and removing the OSGi bundles that are in/placed/updated/removed from that folder at runtime.

I currently have managed to create the ability to startup the embedded Felix and I can deploy bundles if I specify them via BundleContext.installBundle() but I cant get the jar bundles to be dynamically harvested from the hot folder.

This is what I currently have:

public static void main(String[] args) throws Exception {

    System.setProperty("felix.fileinstall.noInitialDelay", "true");
    System.setProperty("felix.fileinstall.poll", "1000");
    System.setProperty("felix.fileinstall.dir", "./hot-deploy");

    System.out.println("Building OSGi Framework");

    FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
    Map<String, String> config = new HashMap<>();

    // make sure the cache is cleaned

    // more properties available at:
    config.put("ds.showtrace", "true");
    config.put("ds.showerrors", "true");

    Framework framework = frameworkFactory.newFramework(config);

    // declarative services dependency is necessary, otherwise they won't be picked up!

    BundleContext context = framework.getBundleContext();
    List<Bundle> installedBundles = new LinkedList<>();


    for (Bundle bundle : installedBundles) {
        if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) {

    try {
    } finally {


private static void loadScrBundle(Framework framework) throws URISyntaxException, BundleException {
    URL url = Activator.class.getClassLoader().getResource("org/apache/felix/scr/ScrService.class");
    if (url == null) {
        throw new RuntimeException("Could not find the class org.apache.felix.scr.ScrService");
    String jarPath = url.toURI().getSchemeSpecificPart().replaceAll("!.*", "");
    System.out.println("Found declarative services implementation: " + jarPath);

How to use FileInstall with apache felix?

I'm trying to use apache felix with file-install

I have created my ManagedService which implements a server connection that needs a host and a port. This two parameters are saved into the config file that should be read by the file-install and then send to my ManagedSevice. I have installed my bundle, the configuration admin bundle and the file-install bundle but it doesn't work.

My configuration file is located into a folder called confFile on my Desktop. I have set all the file-install required information like:

  • felix.fileinstall.dir

  • felix.fileinstall.poll

  • felix.fileinstall.noInitialDelay

Please help me, i have tried all!

Download maven dependency as a single .jar with it’s dependencies included inside

How to download mvn dependency as a single jar with it's dependencies embedded inside ?

My use case:

Downloading(org.apache.felix.http.servlet-api:1.1.0) and then copying it into a folder.

From MVN repository( can get it as a single jar.

In local build I use maven-dependency-plugin:


Now, it copies org.apache.felix.http.servlet-api not as a single jar, but as 2 jar's. First jar is the (org.apache.felix.http.servlet-api), second jar is tomcat-servlet-api. Which is mentioned in the dependency list of my dependency.

How can I just download and copy to a folder org.apache.felix.http.servlet-api as a single jar(same format as download from mvn repository) ?

Thanks, Peter

How to work with datasource in Apache Felix


I was working with some bundles on Apache Karaf sometime back where i install jdbc feature and then putting the datasource-derby.xml file in deploy folder. Everything works perfectly.

I want to have the same setup in Apache Felix. Seems this is missing here.

Can somebody let me know as to work the jdbc commands work like in Karaf, what needs to be done in Felix.


<bean id="dataSource" class="org.apache.derby.jdbc.EmbeddedXADataSource">
   <property name="databaseName" value="test1"/>
   <property name="createDatabase" value="create" />

<service ref="dataSource" interface="javax.sql.DataSource">
        <entry key="" value="jdbc/derbyds"/>

<service ref="dataSource" interface="javax.sql.XADataSource">
        <entry key="" value="jdbc/derbydsxa"/>

Thanks in advance.

Interact with bundle in Apache Felix

I made a program that offers a CLI where you can type a number and calculate the square root of the number typed. I built a bundle starting from this simple application and installed on Apache Felix. The problem is that I can't interact with it (insert a number in the gogo shell) when launched in Felix. Someone has an idea on how to solve this or a work-around to get it works?


Installing OPS4J Pax Web – War Extender

I'm completely new to OSGI and Felix and I'm trying to deploy a simple Jersey project as a bundle on Apache Felix. I installed Pax Web Jetty Bundle and the Runtime. Although, when I try to install Pax Web War Extender I get:

org.osgi.framework.BundleException: Unresolved constraint in bundle org.ops4j.pax.web.pax-web-extender-war [171]: Unable to resolve 171.0: missing requirement [171.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.xbean.finder)(version>=3.18.0)(!(version>=4.0.0)))

I think I'm installing this whole environment wrong, because I had to install small bundles to make others work. Shouldn't they install their own dependencies by themselves? I have these bundles installed and it has been a real pain to make the smallest thing to work with the latest releases:

ID|State |Level|Name 0|Active | 0|System Bundle (4.4.1) 1|Active | 1|Apache Felix Bundle Repository (2.0.2) 2|Active | 1|Apache Felix Gogo Command (0.14.0) 4|Active | 1|Apache Felix Gogo Shell (0.10.0) 10|Active | 1|Apache Felix Configuration Admin Service (1.2.8) 11|Active | 1|Apache Felix EventAdmin (1.2.10) 35|Active | 1|Apache Felix Gogo Runtime (0.12.1) 90|Active | 1|Apache Felix Log Service (1.0.0) 91|Active | 1|OSGi R4 Compendium Bundle (4.0.0) 92|Active | 1|Apache Felix Declarative Services (1.6.0) 93|Active | 1|Apache Felix iPOJO (1.8.0) 94|Active | 1|Apache Felix Web Management Console (3.1.2) 95|Active | 1|Apache Felix iPOJO WebConsole Plugins (1.6.0) 96|Active | 1|Apache Felix Shell Service (1.4.2) 119|Active | 1|Servlet 2.1 API (1.0.0) 144|Active | 1|OSGi JAX-RS Connector ( 147|Active | 1|jersey-all (2.10.1) 157|Active | 1|OPS4J Pax Web - Jetty Bundle (4.0.0) 158|Active | 1|OPS4J Pax Web - Runtime (4.0.0) 163|Active | 1| (0.0.0) 165|Active | 1|Java Servlet API (3.0.1) 167|Active | 1|OPS4J Pax Logging - API (1.8.1) 169|Installed | 1|Apache XBean :: Classpath Resource Finder (3.7.0) 170|Active | 1|Apache Felix Dependency Manager (3.2.0) 171|Installed | 1|OPS4J Pax Web - Extender - WAR (4.0.0) 174|Active | 1|Apache Felix Dependency Manager Runtime (3.2.0)

I tried to install xBean but it depends on several other bundles. How can I solve this? Is there a way that xBean could install those dependencies automatically? PS: I'm simply executing this to install bundles:

g! install http://xyz....
g! start x

Thanks in advance.

How do I actually run Apache Felix OSGi’s shell?

  1. I downloaded the current Felix jar linked over from (for version 4.4.1)
  2. Extracted the .zip
  3. Ran the bin/felix.jar with "java -jar felix.jar"
  4. Observed that the felix-cache/ directory was created

I understand that I should be sitting in the Felix shell there, at that point. But I get no output. I type "help" as per the instructions here:

But I get nothing in terms of a shell. Just a blank terminal that lets me type but doesn't respond at all.

Also, as described in the 'remote shell' instructions, I try to 'telnet localhost 6666' and also get nothing.

Am I wrong in terms of what I'm trying to do? Is the gogo shell a separate application? If not, and I'm correctly expecting to see the shell, where should I look to further debug this issue?

IPOJO logging warning when shutting down

When the application is shutting down and some @Requires services are shutdown, ipojo is logging an exception "The dependency is not optional, however no service object can be injected in A"

public class Main {

   @Requires(id = "A", proxy = false)
   private A aService

   @Bind(id = "A")
   public void bindA(A a) {
       aService = a;

   @Unbind(id = "A")
   public void unbindA() {
       aService = null;

 @Component(imediate = true)
 @Provides(specifications = {A.class})
 public class AImpl implements A {


I suspect (i cannot reproduce the problem on my machine) it might have something to do with proxy = false and/or setting it to null in unbind.