我正在尝试使用Apache Commons Daemon将Tika JAXRS作为Windows服务运行。
我从http://tika.apache.org/download.html得到了tika-server-1.7.jar
我从http://commons.apache.org/proper/commons-daemon/binaries.html下载了Apache Commons Daemon的Windows二进制文件v1.0.15
我可以将Tika作为服务启动,但我无法确定停止方法的用途。
prunsrv.exe //IS//tika-daemon
--DisplayName "Tika Daemon"
--Classpath "C:\Tika Service\tika-server-1.7.jar"
--StartClass "org.apache.tika.server.TikaServerCli"
--StopClass "org.apache.tika.server.TikaServerCli"
--StartMethod main
--StopMethod main
--Description "Tika Daemon Windows Service"
--StartMode java
--StopMode java
这开始了,并且按照我希望的方式工作,但是当试图停止服务时它没有响应。显然org.apache.tika.server.TikaServerCli.main(string[] args)
不是一个合适的停止方法,但我失去了替代品。
我也欢迎任何替代方法,让Tika作为Windows服务运行,或者在交互式会话之外自动启动。
看来这是Apache Commons Daemon 1.0.15的已知问题。 https://issues.apache.org/jira/browse/DAEMON-298
我交换了1.0.14版本,从Apache档案http://archive.apache.org/dist/commons/daemon/binaries/windows/下载,服务现在关闭了。
原始的java
StartMode在关闭时会产生错误但会关闭。然而,exe
StartMode没有问题。
我已经创建了一个MSI,它可以为您完成所有这些:https://github.com/wbicode/TikaService-Installer(或者您可以自己安装设置:https://github.com/wbicode/TikaService)
你必须创建一个单独的类来实现它自己的start / stop-class(tika-server-X.X.jar在它的classpath中)。
public class WinService {
public static void start(String[] args) {
Class<?> clazz = Class.forName("org.apache.tika.server.TikaServerCli");
Method method = clazz.getMethod("main", String[].class);
method.setAccessible(true);
method.invoke(null, (Object)args.toArray(new String[0]));
}
public static void stop(String[] args) {
System.out.println("stopping... TikaService");
Runtime.getRuntime().exit(0);
}
}
并且它与此脚本一起安装(tika-server-X.X.jar位于lib文件夹中):
prunsrv.exe //IS//tika-daemon ^
--DisplayName "Tika Daemon" ^
--Classpath "%SERVICE_PATH%\TikaService.jar;%SERVICE_PATH%\lib\*" ^
--StartMode java ^
--StartClass "your.namespace.WinService" ^
--StartMethod start ^
--StopMode java ^
--StopClass "your.namespace.WinService" ^
--StopMethod stop ^
--Description "Tika Daemon Windows Service" ^