我需要将 Apache Derby 服务器作为服务运行,以便 Derby 与安装它的机器一起启动。
现在,根据我的研究,我尝试了三种解决方案来创建这样的服务,但它们都不可行或产生错误。
使用 Java Service Wrapper:这是不可行的,因为他们只提供 30 天的免费试用。
使用 Windows 服务器管理器 (SrvMgr.exe) 创建如下所述的服务:http ://www.vogella.com/tutorials/ApacheDerby/article.html 。这似乎可行,因为我创建了一个显示在 Windows 注册表中的服务,可以通过“服务”面板启动/停止,并且某些东西正在使用
http://localhost:1527
Derby 服务器的默认地址。但是,如果我尝试通过 eclipse (luna) 或控制台连接到数据库,则会出现错误:Could not connect to DerbyPersistenceDeploy. Error creating SQL Model Connection connection to DerbyPersistenceDeploy. (Error: DERBY SQL error: ERRORCODE: 40000, SQLSTATE: XJ041, SQLERRMC: Failed to create database 'persistence', see the next exception for details.::SQLSTATE: XBM0J) DERBY SQL error: ERRORCODE: 40000, SQLSTATE: XJ041, SQLERRMC: Failed to create database 'persistence', see the next exception for details.::SQLSTATE: XBM0J Error creating JDBC Connection connection to DerbyPersistenceDeploy. (Error: DERBY SQL error: ERRORCODE: 40000, SQLSTATE: XJ041, SQLERRMC: Failed to create database 'persistence', see the next exception for details.::SQLSTATE: XBM0J) DERBY SQL error: ERRORCODE: 40000, SQLSTATE: XJ041, SQLERRMC: Failed to create database 'persistence', see the next exception for details.::SQLSTATE: XBM0J
这是该服务的注册表项的图像:
我绑定的最后一种方法是使用 Apache procrun ( http://commons.apache.org/proper/commons-daemon/procrun.html )。我完成了本教程(http://joerglenhard.wordpress.com/2012/05/29/build-windows-service-from-java-application-with-procrun/)并设法让示例服务运行. 但是,当我尝试调整 tuorial 中发布的脚本时,出现以下错误(来自日志文件):
[2014-07-21 16:52:20] [error] [ 3708] Method 'static void start(String[])' not found in Class org/apache/derby/drda/NetworkServerControl [2014-07-21 16:52:20] [error] [ 6228] Failed to start Java [2014-07-21 16:52:20] [error] [ 6228] ServiceStart returned 4 [2014-07-21 16:52:20] [error] [ 6228] Commons Daemon procrun failed with exit value: 3 (Failed to run service as console application)
这是我改编的用于创建 Web 服务的脚本:
set SERVICE_NAME=DerbyPersistenceService set PR_INSTALL=D:\Program-Files\commons-daemon-1.0.15-bin-windows\prunsrv.exe REM Service log configuration set PR_LOGPREFIX=%SERVICE_NAME% set PR_LOGPATH=D:\04_server\derby\DerbyServiceScript\logs set PR_STDOUTPUT=D:\04_server\derby\DerbyServiceScript\logs\stdout.txt set PR_STDERROR=D:\04_server\derby\DerbyServiceScript\logs\stderr.txt set PR_LOGLEVEL=Error REM Path to java installation set PR_JVM=C:\Program Files (x86)\Java\jdk1.7.0_65\jre\bin\client\jvm.dll set PR_CLASSPATH=%DERBY_HOME%/lib/derby.jar; %DERBY_HOME%/lib/derbynet.jar; %DERBY_HOME%/lib/derbyclient.jar; %DERBY_HOME%/lib/derbytools.jar REM Startup configuration set PR_STARTUP=auto set PR_STARTMODE=jvm set PR_STARTCLASS=org.apache.derby.drda.NetworkServerControl set PR_STARTPARAM=start set PR_STARTMETHOD=main REM Shutdown configuration set PR_STOPMODE=jvm set PR_STOPCLASS=org.apache.derby.drda.NetworkServerControl set PR_STOPPARAM=shutdown set PR_STOPMETHOD=main REM JVM configuration set PR_JVMMS=256 set PR_JVMMX=1024 set PR_JVMSS=4000 set PR_JVMOPTIONS=-Duser.language=US;-Duser.region=en REM Install service D:\Program-Files\commons-daemon-1.0.15-bin-windows\prunsrv.exe //IS//%SERVICE_NAME%
我认为这个错误源于
Startup
- 和Shutdown-Configurations
没有以正确的方式配置但我不知道它们应该是什么样子。
如果有人知道方法 2 或 3 的解决方案,我将不胜感激。
问候
[edit1:] 我按照 Bryan Pendleton 的建议编辑了我的 Procrun 脚本。
[edit2:]服务给了我一个新的错误信息:
stderr.txt
:
2014-07-23 16:41:14 Commons Daemon procrun stderr initialized
stdout.txt
:
2014-07-23 16:41:14 Commons Daemon procrun stdout initialized
Wed Jul 23 16:41:14 CEST 2014 : No command given.
Usage: NetworkServerControl <commands>
Commands:
start [-h <host>] [-p <port number>] [-noSecurityManager] [-ssl <ssl mode>]
shutdown [-h <host>][-p <port number>] [-ssl <ssl mode>] [-user <username>] [-password <password>]
ping [-h <host>][-p <port number>] [-ssl <ssl mode>]
sysinfo [-h <host>][-p <port number>] [-ssl <ssl mode>]
runtimeinfo [-h <host>][-p <port number>] [-ssl <ssl mode>]
logconnections { on|off } [-h <host>][-p <port number>] [-ssl <ssl mode>]
maxthreads <max>[-h <host>][-p <port number>] [-ssl <ssl mode>]
timeslice <milliseconds>[-h <host>][-p <port number>] [-ssl <ssl mode>]
trace { on|off } [-s <session id>][-h <host>][-p <port number>] [-ssl <ssl mode>]
tracedirectory <trace directory>[-h <host>][-p <port number>] [-ssl <ssl mode>]
DerbyPersistenceService.2014-07-23.log
是空的。
我认为方法参数有问题。
[edit3:]更改了脚本,因此它是一个可行的解决方案。非常感谢 Bryan Pendleton 帮助我完成这个。
set SERVICE_NAME=DerbyPersistenceService
set PR_INSTALL=D:\Program-Files\commons-daemon-1.0.15-bin-windows\prunsrv.exe
REM Service log configuration
set PR_LOGPREFIX=%SERVICE_NAME%
set PR_LOGPATH=D:\04_server\derby\DerbyServiceScript\logs
set PR_STDOUTPUT=D:\04_server\derby\DerbyServiceScript\logs\stdout.txt
set PR_STDERROR=D:\04_server\derby\DerbyServiceScript\logs\stderr.txt
set PR_LOGLEVEL=Error
REM Path to java installation
set PR_JVM=C:\Program Files (x86)\Java\jdk1.7.0_65\jre\bin\client\jvm.dll
set PR_CLASSPATH=%DERBY_HOME%/lib/derby.jar;
%DERBY_HOME%/lib/derbynet.jar;
%DERBY_HOME%/lib/derbyclient.jar;
%DERBY_HOME%/lib/derbytools.jar
REM Startup configuration
set PR_STARTUP=auto
set PR_STARTMODE=jvm
set PR_STARTCLASS=org.apache.derby.drda.NetworkServerControl
set PR_STARTPARAMS=start
set PR_STARTMETHOD=main
REM Shutdown configuration
set PR_STOPMODE=jvm
set PR_STOPCLASS=org.apache.derby.drda.NetworkServerControl
set PR_STOPPARAMS=shutdown
set PR_STOPMETHOD=main
REM JVM configuration
set PR_JVMMS=256
set PR_JVMMX=1024
set PR_JVMSS=4000
set PR_JVMOPTIONS=-Duser.language=US;-Duser.region=en
REM Install service
D:\Program-Files\commons-daemon-1.0.15-bin-windows\prunsrv.exe //IS//%SERVICE_NAME%