问题
Trying to run @org.junit.Test with Intellij IDEA.
It's an OSGi bundle, when hit Run 'testMyTest'
Getting following exception:
Error:osgi: [b2b-bundle] 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
Could someone kindly share light on this exception?
Thanks, Peter
回答1:
You probably didn't place your class inside a package.
Add
package your_package_name;
at the top of your .java file and you should be good.
PS: Depending on your package name, you may need to move the file to some other location as well
回答2:
From what I understand about the OSGi library .class files are where they shouldn't be b/c the way this library is structured there are deps in the root package.
Looking at this blog yields more detail.
回答3:
I did fix after remove "classes", "obr" and "\container\tomcat8x\cargo-confluence-home" folder inside "target" then only run atlas-package
回答4:
Add an conditional breakpoint (binaryName.equals(".");) inside the class constructor of aQute.bnd.osgi.Descriptors.PackageRef and check which dependency is making trouble.
回答5:
This error message can also appear due to https://github.com/bndtools/bnd/issues/1848, where the bnd.bnd file has a directive such as e.g. this:
Bundle-Activator: ${classes;IMPLEMENTS;org.osgi.framework.BundleActivator}
and when there is no class that implements BundleActivator, then, confusingly, BND prints that error.
回答6:
In my case, it was the JDOM plugin. Resolution from the blog [1] linked in the currently accepted answer sounds reasonable. Remove the top-level class from JDOM through some arcane pom.xml Maven magic.
It turned out I was pulling JDOM by mistake, because I wrongly declared dependency on the maven-bundle-plugin. I put it into my <dependencies>
, instead of into <build><pluginManagement>
. The plugin depends on JDOM, and I was bundling transitive dependencies. Fixing my dependency declaration cleared the problem.
[1] https://techotom.wordpress.com/2014/10/21/fixing-the-default-package-is-not-permitted-by-the-import-package-syntax-with-maven-bundle-plugin/
来源:https://stackoverflow.com/questions/33395100/the-default-package-is-not-permitted-by-the-import-package-syntax