CodexBloom - Programming Q&A Platform

Eclipse 2023-09: Maven Dependency Conflicts Causing ClassNotFoundException in an OSGi Bundle

👀 Views: 64 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-12
Eclipse Maven OSGi Java

I've been banging my head against this for hours. I'm working on an OSGi bundle within Eclipse 2023-09, and I keep running into a `ClassNotFoundException` when trying to load a specific class from one of my dependencies. The behavior message I'm receiving is: `java.lang.ClassNotFoundException: com.example.MyClass`. I suspect this is due to Maven dependency conflicts, but I need to pinpoint the root cause. In my `pom.xml`, I have the following dependencies: ```xml <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>my-library</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>org.anotherlib</groupId> <artifactId>another-library</artifactId> <version>1.2.3</version> </dependency> </dependencies> ``` I have also defined the necessary exports in my `MANIFEST.MF` file: ```plaintext Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: My OSGi Bundle Bundle-SymbolicName: my.bundle Bundle-Version: 1.0.0 Export-Package: com.example Import-Package: org.anotherlib;version="[1.2.3,2.0.0)" ``` I've tried running `mvn dependency:tree` to check for conflicts, and I noticed that `my-library` has a transitive dependency on `another-library` version `1.0.0`. This seems to clash with the version I am explicitly using in my bundle. I've tried excluding the transitive dependency in my `pom.xml` like this: ```xml <dependency> <groupId>com.example</groupId> <artifactId>my-library</artifactId> <version>1.0.0</version> <exclusions> <exclusion> <groupId>org.anotherlib</groupId> <artifactId>another-library</artifactId> </exclusion> </exclusions> </dependency> ``` However, even after updating the dependencies, I still receive the `ClassNotFoundException`. I've also cleaned my project and updated the Maven project configuration in Eclipse multiple times. Is there a specific way to troubleshoot this further? Could there be issues with how OSGi handles class loading that I'm missing? Any insights on how to resolve this would be greatly appreciated. This is my first time working with Java stable. Any suggestions would be helpful.