2016-10-02 79 views
0

我正在使用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「。

+0

這不是一個代碼問題,因爲它是一個構建/執行的問題。我們需要看到您的CLASSPATH以及您如何調用您的草稿課程。 – Jameson

+0

@jameson我做了一個編輯,請檢查它,也許你可以幫助 –

回答

1

顯然,語言實現本身被打包到單獨的jar中。你需要的是語言en.jar:

https://search.maven.org/remotecontent?filepath=org/languagetool/language-en/3.5/language-en-3.5.jar

你可以在這裏看到:

[email protected]:~$ jar -tf language-en-3.5.jar | grep BritishEnglish 
org/languagetool/language/BritishEnglish.class 

嘗試下載它並將其添加到您的類路徑。另外請務必執行文檔中的項目:http://wiki.languagetool.org/java-api#toc4。我不建議重新打包依賴jar,這是kludgy。我也推薦使用maven來代替。

+1

謝謝,它的工作。 –