Index

Apache Felix

Starting Felix

start felix
java -jar bin/felix.jar
java -jar bin/felix.jar <cache-path>
load bundles in specified directory on startup
java -jar bin/felix.jar -b /path/to/dir
set properties available through BundleContext.getProperty()
java  -jar bin/felix.jar -Dfelix.config.properties=/path/to/property.file

configuration

default config file
[felix_home]/conf/config.properties
change log level
felix.log.level=[level]
0 => off
1 => error (default)
2 => warn
3 => info
4 => debug
set root directory to prefix to relative bundle cache paths
felix.cache.rootdir=/path
set the (relative or absolute) directory to use as bundle cache, will be created if necessary
org.osgi.framework.storage=/path
use this property if you want the bundle cache to be flushed on init
org.osgi.framework.storage.clean=[value]

none (default) => do not flush, in other words, start with the same bundles as last run
onFirstInit => start with a clean OSGI container on init
HTTP specific property for enabling debugging
org.apache.felix.http.debug=true
further reading
https://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Framework+Configuration+Properties
http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html

Command Line Interface

list commands
help
list installed bundles
lb
install bundle
install /path/to/bundle/bundle.jar
install https://example.com/bundle.jar
start bundle
start [id]
stop bundle
stop [id]
remove bundle from cache
uninstall [id]
update bundle from location
update [id] /path/to/bundle/bundle.jar
refresh bundle
refresh [id]
list services registered by bundle
inspect capability service [bundleid]
list services required by bundle
inspect requirement service [bundleid]

Extensions

https://felix.apache.org/downloads.cgi

Web Console

installing the web console
cd [felix-home]/bundles
wget http://apache.cs.utah.edu//felix/org.apache.felix.httplite.complete-0.1.4.jar
wget http://apache.cs.utah.edu//felix/org.apache.felix.webconsole-4.3.4-all.jar
cd ..
java -jar lib/felix.jar
firefox http://localhost:8080/system/console/bundles
admin / admin
web console documentation
http://felix.apache.org/documentation/subprojects/apache-felix-web-console.html
http://felix.apache.org/documentation/subprojects/apache-felix-lightweight-http-service.html

auto deploy using fileinstall

install fileinstall
wget http://mirrors.gigenet.com/apache/felix/org.apache.felix.fileinstall-3.6.4.jar -O [felix-home]/bundle
echo "felix.fileinstall.dir=/path/to/hot/deployment/dir" >> [felix-home]/conf/config.properties
fileinstall documentation
https://felix.apache.org/documentation/subprojects/apache-felix-file-install.html

starting felix from java

launching osgi container
Framework framework = getFrameworkFactory().newFramework(createProperties());
framework.init();
framework.start();
framework.waitForStop(0);

private FrameworkFactory getFrameworkFactory() throws Exception {
	String resource = "META-INF/services/org.osgi.framework.launch.FrameworkFactory";
	java.net.URL url = Main.class.getClassLoader().getResource(resource);
	if (url != null) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
			for (String s = br.readLine(); s != null; s = br.readLine()) {
				s = s.trim();
				// Try to load first non-empty, non-commented line.
				if (s.length() > 0 && s.charAt(0) != '#') {
					return (FrameworkFactory) Class.forName(s).newInstance();
				}
			}
		}
	}
	throw new Exception("Could not find framework factory.");
}
sample properties
private Hashtable<String, String> createProperties() {
	Map<String, String> properties = new Hashtable<>();
	properties.put("org.osgi.framework.storage.clean", "onFirstInit");
	properties.put("org.osgi.service.http.port", "8000");
	properties.put("felix.log.level", "2");
	properties.put("felix.cache.rootdir", root.getAbsolutePath());
	return properties;
}
installing bundles
for (File file : bundleDir.listFiles()) {
	if (file.getName().endsWith(".jar")) {
		Bundle bundle = context.installBundle("file:" + file.getCanonicalPath());
		bundle.start();
	}
}

Further Reading

http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial.html
https://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+File+Install