AEM 6.4 mockito, junits not working - getting java.lang.NoClassDefFoundError | Community
Skip to main content
Level 4
Feb 6, 2019 5:45 PM UTC

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

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.

9 replies

Level 1
May 28, 2019 10:25 PM UTC

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>

Translate
New Participant
Apr 11, 2020 4:18 PM UTC

It worked ! Thanks

Translate
New Participant
May 13, 2019 11:49 AM UTC

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

Translate
Gaurav-Behl
Level 10
Feb 6, 2019 9:14 PM UTC

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

Translate
karanmahiAuthor
Level 4
Feb 7, 2019 5:44 PM UTC

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.

Translate
Gaurav-Behl
Level 10
Feb 7, 2019 6:09 PM UTC

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.

Translate