2016-10-02 83 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

谢谢,它的工作。 –