AEM IntelliJ Debug Error:osgi: [sourcedcode.core] Classes found in the wrong directory: {META-INF/versions/9/javax/xml/bind/ModuleUtil.class=javax.xml.bind.ModuleUtil}

Writing unit tests for AEM Backend code on IntelliJ can sometimes be challenging; mocking objects, initializing OSGI components, etc… It’s most beneficial when we can write unit tests utilizing the JUnit debug feature on IntelliJ.

While trying to debug code in JUnit, I was getting an error of

1
Error:osgi: [sourcedcode.core] Classes found in the wrong directory: {META-INF/versions/9/javax/xml/bind/ModuleUtil.class=javax.xml.bind.ModuleUtil}

Digging through the internet, I have found a solution.

There’s a solution online, https://issues.apache.org/jira/browse/FELIX-5592

Personally, there’s a lot of conversation happening in the post, to offload the confusion for you, I will provide you instructions on how you can solve the problem here.


Step 1

From the core/pom.xml, find the plugin, groupId:org.apache.felix && artifactId:maven-bundle-plugin. Making sure you add _fixupmessages into the instructions XML configuration.

Your configuration should look like below. Add line:9, <_fixupmessages>”Classes found in the wrong directory”;is:=warning</_fixupmessages>

1
2
3
4
5
6
7
8
9
10
11
12
13
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <extensions>true</extensions>
      <configuration>
        <instructions>
          <_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
          ...
    </plugin>
  ...
</build>
Note that the Java-9-specific parts will not be visible in OSGi, because OSGi will need enhancements to its runtime (the problem is that the Java 9 parts could have different dependencies, and OSGi does not support dependencies that are conditional upon the runtime Java version). Work on addressing this limitation is underway. In the meantime, the above snippet will allow you to keep using the maven-bundle-plugin to support OSGi users running on Java 8 and below. FELIX-5592#comment-16281169

Step 2

From the core/pom.xml, make sure you include the required dependency into the project.

1
2
3
4
<dependency>
  <groupId>biz.aQute.bnd</groupId>
  <artifactId>biz.aQute.bndlib</artifactId>
</dependency>

Step 3

From the parent pom.xml, make sure you include the dependency into the project with the correct version.

1
2
3
4
5
<dependency>
  <groupId>biz.aQute.bnd</groupId>
  <artifactId>biz.aQute.bndlib</artifactId>
  <version>3.5.0</version>
</dependency>

Was this post helpful?

Hello, I am an active Adobe Community Advisor & a certified Lead AEM Developer who is currently working as a Senior AEM Full Stack Developer. I have over a decade of overall web engineering experience and many years (more than 6) of AEM experience in practice. I hope to give back to the AEM Full Stack Development community by sharing my knowledge with the world.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top