Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Unable to Find com.adobe.aemfd.docmanager.source.DocumentSourceHandler and How to Work Out java.lang.NoClassDefFoundError

Avatar

Level 1

When I run the following Junit testing code:

 

import com.adobe.aemfd.docmanager.Document;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.*;

class TableOfContentTest {

private Document pdfDoc;
private ProcessInputXML processInputXML;
private TableOfContent tableOfContent;

@BeforeEach
void setUp() throws Exception {
// Load valid PDF content from a file or resource
InputStream pdfInputStream = getClass().getResourceAsStream("/logo.pdf"); // Ensure this file exists in resources
pdfDoc = new Document(pdfInputStream);

// Initialize the ProcessInputXML object
org.w3c.dom.Document inputXML = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
processInputXML = new ProcessInputXML(inputXML);

// Create the TableOfContent instance
tableOfContent = new TableOfContent(pdfDoc, processInputXML);
}
@Test
void shouldThrowAnExceptionOrHandleErrorsForANullTocMap() {

// Use the initialized tableOfContent instance
assertNotNull(tableOfContent);
}
}

 

The error message, java.lang.NoClassDefFoundError: com/adobe/aemfd/docmanager/source/DocumentSourceHandler, occurred at line 24 (

InputStream pdfInputStream = getClass().getResourceAsStream("/logo.pdf");

) and25 (

pdfDoc = new Document(pdfInputStream);

).  How can I find out the best resolution, particularly initialization, to avoid java.lang.NoClassDefFoundError: com/adobe/aemfd/docmanager/source/DocumentSourceHandler?  Thanks for your help.  By the way, when I look for com.adobe.aemfd.docmanager in the import side, I cannot find out source.DocumentSourceHandler.  What version of dependency in Maven repository can include com.adobe.aemfd.docmanager.source.DocumentSourceHandler?  If so, that's great.  Otherwise, what's the best alternative way to be worked out that problem?

2 Replies

Avatar

Employee

Hi @yeouluen0929 

 

This is already discussed here

Or

you can avoid this by using the  org.mockito.Mockito.mockConstruction to simulate the behavior of DocumentProcessInputXML, and TableOfContent

This approach avoids initializing the actual Document object and its dependencies, which may not be available outside the AEM runtime

 

Thanks

Vijendra

Avatar

Level 1

Thanks  @Vijendra1.  Could you also please provide me the codes that can avoid this by using the  org.mockito.Mockito.mockConstruction to simulate the behavior of Document, ProcessInputXML, and TableOfContent and approach avoids initializing the actual Document object and its dependencies, which may not be available outside the AEM runtime?  Thanks.