The default package '.' is not permitted by the Import-Package syntax
Asked Answered
C

8

11

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

Craigcraighead answered 28/10, 2015 at 15:27 Comment(1)
Yep, have been googling found couple of blog posts about it. When I do clean install it works, in eclipse it works, in intellij it does not... does not use jdomCraigcraighead
L
8

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

Luminous answered 22/12, 2015 at 11:14 Comment(0)
P
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.

Practiced answered 28/10, 2015 at 15:34 Comment(3)
This bundle has 143 Bundle's under it's dependencies declaration, it does not use the JDom too...Craigcraighead
I know that the particular example shown in the blog uses JDom, but essentially you have the same issue. There is something wrong with the location of your dependencies. Add more of the error output so its easier to analyze.Practiced
Oh you figured it out? NVM but yeah since left over .class files were messing up your build I guess doing "clean install" would fix the problem lol.Practiced
J
1

I did fix after remove "classes", "obr" and "\container\tomcat8x\cargo-confluence-home" folder inside "target" then only run atlas-package

Javierjavler answered 23/11, 2017 at 10:43 Comment(0)
F
0

Add an conditional breakpoint (binaryName.equals(".");) inside the class constructor of aQute.bnd.osgi.Descriptors.PackageRef and check which dependency is making trouble.

Fromenty answered 29/11, 2016 at 17:7 Comment(0)
D
0

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.

Defilade answered 20/1, 2017 at 5:28 Comment(0)
S
0

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/

Sneaky answered 12/11, 2017 at 14:13 Comment(0)
A
0

There MAY be a dependency that causes that error (using default package). You just should find it.

In my case, I accepted such error while doing "atlas-package" for packaging plugin.

In my case that was a dependency:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>4.1.6.RELEASE</version>
</dependency>

Happily, that was not critical, so I just remove it.

Atonic answered 17/7, 2020 at 8:26 Comment(0)
A
0

If you use Maven, just use

mvn clean

It resolved my issue. I'm inspired by @Landaida

Acetify answered 5/8, 2022 at 2:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.