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> |
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> |