Hello,
I’m trying to use languagetool in a simple java application (using Netbeans). I successfully used the languagetool in a maven project as it is described in your site but I wonder if it is possible to use languagetool without maven.
What are the steps to implement the simple example of Embedding LanguageTool in Java applications?
I cant figure out what jars I should include.
Without Maven, download the *.zip from our homepage (“Download LanguageTool for stand-alone use”). You will need to include all the JARs in the “lib” directory and create a JAR of everything in the “org” directory.
I did the following:
- added all jars ( from the directory : \LanguageTool-2.3\LanguageTool-2.3\libs )
-and my program looks like this:
...
import org.languagetool.JLanguageTool;
import org.languagetool.language.BritishEnglish;
import org.languagetool.rules.RuleMatch;
..
// the simple code example of your site:
JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
for (Rule rule : langTool.getAllRules()) {
if (!rule.isSpellingRule()) {
langTool.disableRule(rule.getId());
}
}
List<RuleMatch> matches = langTool.check("A speling error");
for (RuleMatch match : matches) {
System.out.println("Potential typo at line " +
match.getLine() + ", column " +
match.getColumn() + ": " + match.getMessage());
System.out.println("Suggested correction(s): " +
match.getSuggestedReplacements());
}
...
but there’s a problem with “import org.languagetool.language.BritishEnglish;” it says cannot find symbol " class BritishEnglish " in the package org.languagetool.language.
I apologize for insisting to get a specific answer for something probably very easy but I m not familiar with this and I hope this thread will be helpful for others to use Languagetool
BritishEnglish is in the “org” directory and not in the JARs, but you can put in a JAR like this: “zip -r languages.jar org/”, then add languages.jar to your classpath like the other JARs.
My long term advice would be to use Maven (or a similar system like Gradle). It’s quite a complex tool but it pays off in the long run.
Thank you very much for your reply.I’ve tried many useless ways in order to make it work till I decided to use the forum. Finally I am able to use it in my program.
using languageTool in a simple java application it’s ok! (a function with parameter the phrase I want to do spelling correction)
But calling the same function in a servlet throws exception. I’ve read that probably it has to do with the concurency and threads, is that the problem ? Can you give me any hint ?( how can I find out what is the exact problem ? )
Actually I wasn’t very clear: I m getting a general IOexception calling the initial function that was working fine(I didn’t change a single line).
The problem is located just before the creation of the LanguageTool object , I just call my function in a servlet , everything else works fine in my project,the appropriate jar files are included , I just can’t use the specific function for the spelling correction and I don’t know how to catch a more detailed exception in order to solve it due to my poor java skills.
actually i am also facing same error.
but go through this site i can’t understand.
“zip -r languages.jar org/”—how do i use?.
can you please explain me clearly?
After “zip -r languages.jar META-INF/ org/” you need to add languages.jar to your classpath. How to do that exactly depends on your local environment or IDE.
zip -r languages.jar org/ when used on command mode it shows error as
“zip is not recognized as an internal or external command”.
Is that to be used in command mode. Please explain.
Also, If i zip the Org folder and create it as a jar, i cannot import it in my java code.
Please assist.
I was having the same exact problem with my IDE not being able to find the BritishEnglish class. I have made the the language folder into a jar and added it the libraries the same way I did with the other JAR files. I also made the language-module under META-INF/org a jar file and added that as well.
I was able to get Language Tools to run as a standalone so I should have everything necessary and I believe I have put everything from the language tools program in my project classpath.
Sorry for being so specific but I have been trying for the past three days to get LT to work, I even tried using maven but was getting many more errors that I was having trouble figuring out the meaning of.
You’d need to make the top-level org directory a JAR file, not the one below META-INF. But even that isn’t needed, as long as you simply add the top-level org to the classpath (together with all the JARs in the libs directory).
I have added the top level org as well as all the JARS in the libs and the program still won’t compile. The only error i am getting is with the British English. I’ve tried JAR ing the language folder as well as the BritishEnglish.class and adding that but still I am having no luck. I do not understand what I could be doing wrong. Please let me know if you have any ideas.
Is also coming up saying it is an unused import, so it seems obvious that the program cannot find the BritishEnglish.class in the languages folder but I don’t know why.
I would say managing jars manually in Java projects is not recommended exactly for this reason: it’s really time-consuming to do it right and it’s really easy to break it if something changes.
Maven and Gradle are excellent build systems that make things so much easier and they will make sure your build is correct and all the necessary jars with correct versions are pulled in.
I was originally trying to use Maven but have no experience with it and was getting multiple error messages. I started with a simple Hello World Maven app and then tried adding the dependency and code that the API suggests but still couldn’t get the program to compile. The last error it gives is MojoFailureException, which when you look up, tells me the problem is something with the plugin I am trying to use. I tried scrolling through errors to see the source of the problem but cannot even get all of them because the command prompt cuts off some of them due to how many there are.