Back to LanguageTool Homepage - Privacy - Imprint

Using Java API with Maven


(rob144) #1

Hi,

I recently came across the LanguageTool project and as a developer I would like to play around with the Java API but thus far have been unable to get this working with Maven.

As per http://wiki.languagetool.org/java-api I have added the dependency to the Maven pom.xml config file for my project and have added a simple test class App.java with the following code:

package com.rd.test1;
import java.util.List;
import org.languagetool.JLanguageTool;
import org.languagetool.language.BritishEnglish;
import org.languagetool.rules.RuleMatch;
public class App
{
public static void main( String[] args )
{
JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
langTool.activateDefaultPatternRules();
List 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());
}
}
}

However after running the mvn package command it fails with compilation errors which refer to the line and character positions where I'm using the LT objects.

Despite having added the dependency it seems Maven is not finding or importing the LT classes.

[ERROR] ...src/main/java/com/rd/test1/App.java:[11,33] error: unreported exception IOException; must be caught or declared to be thrown
[ERROR] .../src/main/java/com/rd/test1/App.java:[12,44] error: unreported exception IOException; must be caught or declared to be thrown
[ERROR] .../src/main/java/com/rd/test1/App.java:[13,48] error: unreported exception IOException; must be caught or declared to be thrown

Could you please advise any troubleshooting steps here?

I think LT is a fantastic project! I just wish I could use the API successfully.

Any assistance would be most gratefully appreciated :smile:

Thanks
Rob


(Daniel Naber) #2

Some of the methods throw an IOException, so you will need to add "throws IOException" to your main method.