// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a resource provider
ResourceProvider provider = new ResourceProvider(e);
// activate it
m.add(m.createComponent().setImplementation(provider).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add", "remove")));
// create a resource adapter for our single resource
// note that we can provide an actual implementation instance here because there will be only one
// adapter, normally you'd want to specify a Class here
m.add(m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, null, "changed")
.setImplementation(new ResourceAdapter(e)));