我正在使用this示例代碼來使用API。我不想使用maven,因此我從here下載了jar文件,並將org和lib中的jar文件包含到構建路徑中,然後嘗試運行示例代碼。我得到這個錯誤:java語言工具庫,無法找到依賴關係
Error:(15, 56) java: cannot find symbol
symbol: class BritishEnglish
location: class draft
Error:(3, 34) java: cannot find symbol
symbol: class BritishEnglish
location: package org.languagetool.language
這裏是我的代碼
import org.languagetool.JLanguageTool;
import org.languagetool.language.BritishEnglish;
import org.languagetool.rules.RuleMatch;
import java.io.*;
import java.util.List;
public class draft {
public static void main(String[] args) throws IOException {
JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
// comment in to use statistical ngram data:
//langTool.activateLanguageModelRules(new File("/data/google-ngram-data"));
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 characters " +
match.getFromPos() + "-" + match.getToPos() + ": " +
match.getMessage());
System.out.println("Suggested correction(s): " +
match.getSuggestedReplacements());
}
}
}
我發現這個答案在網上,但我不明白。
「BritishEnglish位於」org「目錄中,不在JAR中,但可以像這樣放入JAR:」zip -r languages.jar org /「,然後將language.jar添加到類路徑中,如其他JAR「。
這不是一個代碼問題,因爲它是一個構建/執行的問題。我們需要看到您的CLASSPATH以及您如何調用您的草稿課程。 – Jameson
@jameson我做了一個編輯,請檢查它,也許你可以幫助 –