简体   繁体   中英

Languagetool example: java.lang.NoSuchMethodError: org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar

The error message java.lang.NoSuchMethodError: org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar shows up when I try to run the example from

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

the solution offered in: java.lang.NoSuchMethodError: org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar

would mean that the Xerces specified in LanguageTools dependency would be the one creating the trouble.

mvn dependency:tree | grep -i xerces

does not show any result and in Languagetools pom.xml Xerces is explicitly excluded.

my own test project has the following xerces dependencies:

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

I assume I have do get rid of one of these dependencies, change the order of dependencies or add the correct xerces dependency for LanguageTool. What would be the right approach - one of these or something else?

According to oracle documents This Error is

Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM