错误消息java.lang.NoSuchMethodError: org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar 当我尝试运行示例时出现
http://wiki.languagetool.org/java-api
JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
langTool.activateDefaultPatternRules();
List<RuleMatch> matches = langTool.check("A sentence " +
"with a error in the Hitchhiker's Guide tot he Galaxy");
for (RuleMatch match : matches) {
System.out.println("Potential error at line " +
match.getLine() + ", column " +
match.getColumn() + ": " + match.getMessage());
System.out.println("Suggested correction: " +
match.getSuggestedReplacements());
}
提供的解决方案: java.lang.NoSuchMethodError: org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar
这意味着 LanguageTools 依赖项中指定的 Xerces 将是造成麻烦的原因。
mvn 依赖项:树 | grep -i xerces
不显示任何结果,并且在 Languagetools pom.xml 中 Xerces 被明确排除。
我自己的测试项目具有以下 xerces 依赖项:
mvn dependency:tree | grep -i xerces
[INFO] | | | | +- org.bluestemsoftware.open.maven.tparty:xerces-impl:jar:2.9.0:compile
[INFO] | | | | \- xerces:xercesImpl:jar:2.6.2:compile
我假设我已经摆脱了这些依赖项之一,更改依赖项的顺序或为 LanguageTool 添加正确的 xerces 依赖项。什么是正确的方法 - 其中之一还是其他方法?
最佳答案
根据oracle文档这个错误是
如果应用程序尝试调用类(静态或实例)的指定方法,并且该类不再具有该方法的定义,则抛出此异常。 通常,这个错误会被编译器捕获;仅当类的定义发生不兼容的更改时,此错误才会在运行时发生。
关于java - Languagetool 示例 : java. lang.NoSuchMethodError : org. apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25907679/