Listing loaded OSGI Bundles in Lucee

Updated , First Published by Pete Freitag

Here's a quick code snippet that will output a list of OSGI java bundles and bundle versions that are loaded / installed on Lucee:

//CFMLEngine
engine = getPageContext().getCFMLFactory().getEngine();

//org.osgi.framework.BundleContext
bundleContext = engine.getBundleContext();

//array of org.osgi.framework.Bundle objects
bundles = bundleContext.getBundles();

for (b in bundles) {
  writeOutput(b.getSymbolicName() & ":" & b.getVersion() & "<br>");
}

Here's a link to run the code on trycf. It was inspired by the "getBundles" action of the cfadmin tag (source).

You might be wondering why not just use the cfadmin tag, well it requires a password for all operations, which makes sense for many of the operations, but I don't think it should be necessary to list the bundles.

The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.