How to fix “The default package ‘.’ is not permitted by the Import-Package syntax” in OSGI

2 min readJan 16, 2024

When you build your OSGI project with “org.apache.felix:maven-bundle-plugin” you can found error like this:

[ERROR] Bundle {groupId}:{artifactId}:bundle:{version} : The default package ‘.’ is not permitted by the Import-Package syntax.
This can be caused by compile errors in Eclipse because Eclipse creates
valid class files regardless of compile errors.
The following package(s) import from the default package null
[ERROR] Error(s) found in bundle configuration

That means that one of your dependent packages places their class in root (default package). Unfortunately the error message describes that issue exists but doesn’t tell the source of the problem.

Example Jar with classes in default package

You can debug this on one’s own. Add “org.apache.felix:maven-bundle-plugin” as a dependency with scope=test. That will allow you to create the break point.

Add a conditional breakpoint into “aQute.bnd.osgi.Packages” class in all places where values inserts into “Map<PackageRef, Attrs> map” with condition that key contains “Descriptors.DEFAULT_PACKAGE”:

How to create conditional breakpoint

When this breakpoint is triggered go to frame “analyzeJar” and look at the resource that represents the jar with the default package.

How to find resource with class in default package

You have to replace dependency with another version that doesn’t contain a class inside the default package. In my case updating the library “dnsjava:dnsjava” to the latest version fixed the problem.

--

--

No responses yet