google-diff-match-patch在运行时因java.lang.NoClassDefFoundError而失败

时间:2014-12-18 17:34:51

标签: java google-diff-match-patch

我正在尝试使用google-diff-match-patch,在运行以下代码时在diff_match_patch $ Diff上获取NoClassDefFoundError。

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);
}

我看过编译后的diff_match_patch.class和diff_match_patch $ Diff,diff_match_patch $ Patch和diff_match_patch $ LinesToCharsResult都在那里。我对静态嵌套类没有太多运气,但我认为这就是问题所在。

1 个答案:

答案 0 :(得分:1)

我使用Makefile来构造我正在使用的jar,我需要在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