google-diff-match-patch failing at runtime with java.lang.NoClassDefFoundError

414 views Asked by At

I am trying to use google-diff-match-patch, getting a NoClassDefFoundError on diff_match_patch$Diff when I run the following code.

import name.fraser.neil.plaintext.diff_match_patch.Diff;
import name.fraser.neil.plaintext.diff_match_patch.LinesToCharsResult;
import name.fraser.neil.plaintext.diff_match_patch.Patch;

...

public static void difftest(){
    String string1 = "My first string";
    String string2 = "My second string";

    diff_match_patch dmp = new diff_match_patch();
    LinkedList<Diff> diffs= dmp.diff_main(string1, string2);
    String html = dmp.diff_prettyHtml( diffs);
    System.out.println(html);
}

I've looked at the compiled diff_match_patch.class and diff_match_patch$Diff, diff_match_patch$Patch, and diff_match_patch$LinesToCharsResult are all there. I've never had much luck with static nested classes, but I think that's where the problem is.

1

There are 1 answers

0
Adam D On

I was using a Makefile to construct the jar I'm using, and I needed to include the nested classes in the jar

CLASSES = $(SRCS:.java=.class)  \
    diff_match_patch$$Diff.class \
    diff_match_patch$$Patch.class \
    diff_match_patch$$LinesToCharsResult.class \
    diff_match_patch$$Operation.class \
    diff_match_patch$$1.class