Dynamic loading of language-* modules


I’ve developing GUI application OmegaT which uses LanguageTool 6.1 as optional dependency for users.
Currently, we bundle all the language-* modules with an application distribution as same as other depended libraries.

Because LanguageTool is not mandatory for running the application, I’d like to made language-* jar files as plugins and dynamic loading after starting the application.

When trial, I found LanguageTool-core does not recognize these class paths because it is initialized in static context. So I tried to use Languages.getOrAddLanguageByClassName to pass dynamic loaded org.languagetool.language.French of language-fr-6.1.jar but it raises ClassNotFound error.

The class org.languagetool.language.French can be loaded by this.class.getClassLoader().loadClass("org.langaugetool.language.French") successfully, so languagetool has special treatment for it.

I’m also trying custom ClassBroker definition that is

public static class ClassBrokerBroker implements ClassBroker {
    public Class<?> forName(String classname) {
        ClassLoader classloader = ClassBrokerBroker.class.getClassLoader();
        return classloader.loadClass(classname);

that load the class org.languagetool.language.French but it also raises ClassNotFound error for org.languagetool.language.tagger.fr.FrenchTagger class.

I’d like to contribute for improvement, I’ve start topic PR in feat: allow loading language-* module as plugins in application by miurahr · Pull Request #9447 · languagetool-org/languagetool · GitHub
to make things delayed to happened to make language list just when languagetool accessed.

1 Like