How to run tika-server as a windows service using Apache Commons Daemon

I have submitted a PR to the Apache Tika project for this, we'll see if they merge it.

Using Apache Commons Daemon you can host tika-server as a windows service. However, tika-server has no static method for stopping the server, so once started it's impossible to stop the windows service. Not really ideal.

To fix this, you need build from source and add a stop method to and to

static TikaServerWatchDog watchDog = null;

private static Options getStopOptions()
    Options options = new Options();
    options.addOption("preventSystemExit", false, "Prevent the stop method from calling system.exit, which will terminate the JVM. This is useful for integration tests.");
    return options;

private static void execute(String[] args) throws Exception {
        Options options = getOptions();

        CommandLineParser cliParser = new GnuParser();
        //need to strip out -J (child jvm opts) from this parse
        //they'll be processed correctly in args in the watch dog
        //and they won't be needed in legacy.
        CommandLine line = cliParser.parse(options, stripChildArgs(args));
        if (line.hasOption("spawnChild")) {
            /*TikaServerWatchDog watchDog = new TikaServerWatchDog();*/
            watchDog = new TikaServerWatchDog();
            watchDog.execute(args, configureServerTimeouts(line));
        } else {
            if (! line.hasOption("child")) {
                //make sure the user didn't misunderstand the options
                for (String childOnly : ONLY_IN_SPAWN_CHILD_MODE) {
                    if (line.hasOption(childOnly)) {
                        System.err.println("The option '" + childOnly +
                                "' can only be used with '-spawnChild'");
            executeLegacy(line, options);

public static void stop(String [] args) {
    // process service stop function
    if(watchDog != null)
        Options options = getStopOptions();
        CommandLineParser cliParser = new GnuParser();
        CommandLine line = cliParser.parse(options, args);
        if (line.hasOption("preventSystemExit")) {
    catch (org.apache.commons.cli.ParseException e){
        LOG.error("Can't parse stop arguments: ", e);

public void close()
    LOG.debug("about to shutdown");
    if (childProcess != null) {"about to shutdown process");

Once that's built, take your new jar file, and you'll be able to set it up with Apache Commons Daemon.

Install as a windows service

C:\source\tika\commons-daemon-1.2.2-bin-windows\amd64\prunsrv.exe //IS//tika-daemon ^
--DisplayName "Tika Daemon"  ^
--Description "Tika Daemon Windows Service" ^
--Classpath C:\source\tika\tika-server.jar ^
--StartClass "org.apache.tika.server.TikaServerCli" ^
--StopClass "org.apache.tika.server.TikaServerCli" ^
--StartMethod main ^
--StopMethod stop ^
--StartMode jvm  ^
--StopMode jvm ^
--StdOutput auto ^
--StdError auto ^
--Jvm "C:\Program Files\Java\jdk1.8.0_211\jre\bin\server\jvm.dll" ^
++StartParams -spawnChild 

Once installed, you can double click the renamed "tika-daemon.exe" and view the configuration. If the service fails to start, configure the logging options to inspect the output. In my case I had trouble with both the JVM AND the archicture. Above you'll see I'm using the 64bit prunsrv.exe and I've manually set the JVM dll path.


--Jvm "C:\Program Files\Java\jdk1.8.0_211\jre\bin\server\jvm.dll" ^


Once done, tika will be up and running on the default port. Additional configuration can be provided inside the ++StartParams options


AND... it works