Samstag, 23. März 2013

JDK8: Unable to Resolve javax.swing ?

The other day I was running an OSGi project with JDK8 and noticed, that the javax.swing package could not be found. This worked in JDK7. Switching to JDK8 in osgisnippets was leading to the following error, when Swing is about to be loaded:

org.osgi.framework.BundleException: Unresolved constraint in bundle example.swing1 [1]: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (osgi.wiring.package=javax.swing) at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826) ~[org.apache.felix.main-4.0.2.jar:na] at org.apache.felix.framework.Felix.startBundle(Felix.java:1868) ~[org.apache.felix.main-4.0.2.jar:na] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944) ~[org.apache.felix.main-4.0.2.jar:na] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:931) ~[org.apache.felix.main-4.0.2.jar:na] ...

The reason is simple: A Felix version was used, which does not know about JDK8. Upgrading to a newer version like org.apache.felix.main-4.2.1.jar solves the issue.

The OSGi framework makes java.* packages available automatically. The JDK contains several packages outside the java.* namespace such as javax.swing or org.xml.sax, which are made available too, but specific to the Java version. The felix main jar contains a file default.properties which also defines the exported packages for each Java version. So felix detected jre-1.8, but in the default.properties file of v4.0.2 there is no entry for that. Hence all the extra JRE packages (other than java.*) were not exported.

Resources

Keine Kommentare:

Kommentar veröffentlichen