简体   繁体   中英

Felix: unable to add extension bundle on JDK 9

Upon migration to JDK 9+, our OSGi container built around apache Felix started to fail installing an extension bundle. The error message is:

Caused by: org.osgi.framework.BundleException: Could not create bundle object.
    at org.apache.felix.framework.Felix.installBundle(Felix.java:3095)
    ...
Caused by: java.lang.UnsupportedOperationException: Unable to add extension bundle.
    at org.apache.felix.framework.ExtensionManager.addExtensionBundle(ExtensionManager.java:439)
    at org.apache.felix.framework.Felix.installBundle(Felix.java:3061)
    ...

Our Felix version is 5.6.10, which is currently the latest available. Relevant part of the bundle manifest:

Created-By: Apache Maven Bundle Plugin
Fragment-Host: system.bundle; extension:=framework
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=9.0))"
Tool: Bnd-3.5.0.201709291849

Debugging revealed that the class loader used to install the extension has been moved to a named module in JDK 9. The class loader's package must therefore be opened for all unnamed modules in order to be reachable from the Felix framework.

It works after adding the following command-line option:

--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED

For unit tests with maven-surefire-plugin, use:

 <configuration>
     <argLine>
         --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED
     </argLine>
 </configuration>

The solution seems to be logged from Felix' ExtensionManager , but not added to the exception message, so the message was not found in my own logs:

        m_logger.log(bundle, Logger.LOG_WARNING,
            "Unable to add extension bundle - Maybe ClassLoader is not supported " +
                    "(on java9, try --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED)?");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM