AEM 6.4 mockito, junits not working - getting java.lang.NoClassDefFoundError | Community
Skip to main content
Level 4
February 6, 2019

AEM 6.4 mockito, junits not working - getting java.lang.NoClassDefFoundError

  • February 6, 2019
  • 3 replies
  • 12269 views

After 6.4 upgrade, junits giving below mentioned error (Using Mockito for junits). This used to work in AEM 6.3. We looked at the packages inside Uber-jar-6.4.3-apis.jar (inside maven dependencies of eclipse ), and noticed that package "org.apache.sling.api.wrappers" is showing empty? ObjectConverter class which is not found is being referred from this package. Since the package is not present, we won't find this class. Is there any way we can fix it?

java.lang.NoClassDefFoundError: org/apache/sling/api/wrappers/impl/ObjectConverter

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Gaurav-Behl
Level 10
February 6, 2019

I believe this wrapper package implementation gets resolved via other transitive dependencies

check this  --

/**
* This is copied from org.apache.sling.api.wrappers.impl.ObjectConverter
* to avoid dependency to latest Sling API.
* This can be removed when Sling API 2.17.0 or higher is referenced.
*/

sling-org-apache-sling-fsresource/ObjectConverter.java at master · apache/sling-org-apache-sling-fsresource · GitHub

karanmahiAuthor
Level 4
February 7, 2019

gauravb10066713 - What changes do you suggest to fix this, because our junits are looking for ObjectConverter in this package org/apache/sling/api/wrappers/impl/ObjectConverter through transitive dependency.

Gaurav-Behl
Level 10
February 7, 2019

You would need to update/fix your pom.xml per requirement with specific library versions and specific scope. It also depends on what maven archetype do you currently use and other osgi/scr annotation versions.

You may want to check WKND tutorial poms and take a reference about what versions are included. Alternatively, you may share your project code/pom.xmls so that I could check it.

May 13, 2019

HI,

did you find an answer to this error?

I am facing the same issue.

I am upgrading from AEM 6.2 to AEM 6.5.

java.lang.NoClassDefFoundError: org/apache/sling/api/wrappers/impl/ObjectConverter

        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)

        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

        at org.apache.sling.api.wrappers.ValueMapDecorator.get(ValueMapDecorator.java:56)

        at org.apache.sling.testing.resourceresolver.DeepReadModifiableValueMapDecorator.get(DeepReadModifiableValueMapDecorator.java:73)

        at org.apache.sling.testing.resourceresolver.MockValueMap.get(MockValueMap.java:87)

        at org.apache.sling.testing.resourceresolver.MockResource.getResourceType(MockResource.java:71)

        at x.x.x.x.models.TestHelloWorldModel.testHelloWorld(TestHelloWorldModel.java:44)

Regards,

Prateek

Level 1
May 28, 2019

Try adding this to your POM (notice its scoped to test)

            <dependency>

                <groupId>org.apache.sling</groupId>

                <artifactId>org.apache.sling.api</artifactId>

                <version>2.18.4</version>

                <scope>test</scope>

            </dependency>

April 11, 2020

It worked ! Thanks