How to set up your own instance of LanguageTool

What do I download to set up my own instance of LanguageTool? Where do I get it?

Thanks

P

UPDATE: there’s documentation about setting up your own LT server at LanguageTool embedded HTTP Server | dev.languagetool.org

Just download the stand-alone version of LT from https://languagetool.org. It contains languagetool-server.jar that will print its usage when called like java -jar languagetool-server.jar. Alternatively, start the stand-alone version and activate the server under Text Checking -> Options -> Run as server.

I tried to run languagetool-server.jar and got the following:

root@server [/home/esprimme/public_html/lt]# java -jar languagetool-server.jar
Exception in thread “main” java.lang.UnsupportedClassVersionError: org/languagetool/server/HTTPSServer : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

What’s up here?

Patrick

You need Java 8 to run LanguageTool 3.3, it seems you’re still on Java 7.

Thanks Daniel. I upgraded my server account and the LanguageTool server started. However, I am not able to connect through my browser or with Telnet.

P

Which URL did you use to connect? What happened then, did you get an error message?

Daniel:

I checked with my hosting service and they told there were two issues: the server’s firewall and the need to set up a system-5 compatible (init.d) service script.

I’ve taken care of the firewall. However they indicate that I need an example of a service script from you. Can you help?

Thanks

P

We don’t provide such a script officially, maybe someone else here one this forum can post theirs.

Here’s the file I created for my server. It’s not a ready solution for you but it’s a good template to start with.
You will need to adjust the start script (currently I have a script with hardcoded classpath) and when I stop I kill all java processes as I know LT is the only java process on my server. You may need to be more specific (i.e. store PID when you start and kill by that PID).
http://r2u.org.ua/data/tmp/lt

Setting up LanguageTool to run on one’s own server is not necessarily straightforward. In my case, having a hosted virtual private server, there are some additional hoops to jump through. You will need shell access to the server root, thus most accounts that are a shared service controlled by cPanel, you will not be able to create a permanent, stable, secure instance.

There a number of things that have recommended to me by hosting service

  • create a special user with no login privileges. You can see how to do this at (15 Useful Useradd Commands with Examples in Linux)
  • configure your firewall to enable port 8081 (or whichever port you choose)
  • a service script is needed (more on that below)

I found a template for a service script for my server–running Centos 7-- at AppsInTheOpen

I have modified the template for my installation, as follows, but there are a couple of items I’m not sure how to handle.

#!/bin/sh
#
# <ltoold> <summary>
#
# chkconfig:   - 20 80
# description: <description, split multiple lines with \
#              a backslash>

# Source function library.
. /etc/rc.d/init.d/functions

exec="java -cp /home/ltool/languagetool-server.jar org.languagetool.server.HTTPServer --port 8081"
prog="languagetool"
config="/home/ltool/"                   **<----- Is there a configuration file associated with LanguageTool?**

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6
    echo -n $"Starting $prog: "
    # if not running, start it up here, usually something like "daemon $exec"
#=======================
# It has been suggested that I use something like to the following to start LanguageTool
#  cd /home/ltool
#  sudo -u ltool java -cp languagetool-server.jar org.languagetool.server.HTTPServer --port 8081
# since it's multiline, I may have to put this in a file (i.e., startlt.sh)
#=======================
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
stop
start
}

reload() {
restart
}

force_reload() {
restart
}

rh_status() {
# run checks to determine if the service is running or use generic status
status $prog
}

rh_status_q() {
rh_status >/dev/null 2>&1
}


case "$1" in
start)
    rh_status_q && exit 0
    $1
    ;;
stop)
    rh_status_q || exit 0
    $1
    ;;
restart)
    $1
    ;;
reload)
    rh_status_q || exit 7
    $1
    ;;
force-reload)
    force_reload
    ;;
status)
    rh_status
    ;;
condrestart|try-restart)
    rh_status_q || exit 0
    restart
    ;;
*)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
    exit 2
esac
exit $?

Well, that’s it for now.
P

For myself, running the server on my notebook with FreeBSD-CURRENT, I chose this:

#!/bin/sh
( cd /usr/home/grahamperrin/dev/LanguageTool && java -jar languagetool.jar --tray & )
cd /usr/home/grahamperrin/dev/LanguageTool
( java -cp languagetool-server.jar org.languagetool.server.HTTPServer --port 8081 --allow-origin "*" & )

Run as a login script through Autostart preferences in KDE Plasma.

The command line start of the server is debatably unnecessary, in that I could instead use the tray icon to run the server:

image

– however there might be times when I’ll want to quit the application but continue using the server, so I don’t use the app in that way.


Incidentally, if I run the line for the server at the command line there’s trailing output, for example:

% uname
FreeBSD
% ( java -jar languagetool.jar --tray & )
% WINDOW DECORATIONS RELOADED

% ( java -cp languagetool-server.jar org.languagetool.server.HTTPServer --port 8081 --allow-origin "*" & )
% 2021-02-02 19:44:55 +0000 INFO  org.languagetool.server.DatabaseAccess Not setting up database access, dbDriver is not configured
2021-02-02 19:44:55 +0000 WARNING: running in HTTP mode, consider running LanguageTool behind a reverse proxy that takes care of encryption (HTTPS)
2021-02-02 19:44:57 +0000 Setting up thread pool with 10 threads
2021-02-02 19:44:57 +0000 Starting LanguageTool 5.2 (build date: 2020-12-29 15:54, eb572bf) server on http://localhost:8081...
2021-02-02 19:44:57 +0000 Server started
…

– is there any way to avoid this? I can simply ignore it, or close the tab (without stopping the server) but I’m curious about this type of thing.

I see answers at, for example:

– however I don’t fully understand some of what’s there.

NB no disown with FreeBSD.

Try java -cp languagetool-server.jar org.languagetool.server.HTTPServer --port 8081 --allow-origin "*" & >/dev/null 2>&1 to ignore printed output.