我需要将Apache Derby Server作为服务运行,以便Derby与安装它的机器一起启动。
现在我尝试了三种解决方案 - 基于我的研究 - 创建这样的服务,但它们都不可行或产生错误。
使用Java Service Wrapper:这是不可行的,因为它们只提供30天免费试用。
使用Windows Server Manager(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)
这是我用来创建网络服务的改编脚本:
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:]我编辑了我的Procrun脚本,就像Bryan Pendleton建议的那样。
[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%
答案 0 :(得分:2)
我认为PR_STARTMETHOD和PR_STOPMETHOD应该是&#39; main&#39;,因为你想调用NetworkServerControl的main()方法。
我相信&#39;开始&#39;和&#39;关闭&#39;是参数,你需要传递给main()方法。
所以他们应分别进入STARTPARAMS和STOPPARAMS。
答案 1 :(得分:0)
我遇到了同样的问题并尝试使用各种各样的工具和包装器来将Derby作为Windows服务,其中包括Derby wiki(http://wiki.apache.org/db-derby/DerbyWindowsService)中描述的所有方式。
无论如何,这些工具都不适用于我,除了Appache基金会提供的procrun工具,它在tomcat中用于将此服务器作为Windows服务器。所以,请按照以下步骤操作:
要在Windows上创建服务,您必须执行下一个脚本。它被编写为在Derby文件夹的上层文件夹(..)上执行,并使用可移植版本的java 32位。
Derby \ bin \ derby.exe // IS // DerbyService
--DisplayName =“德比服务”
--Description =“这是Derby数据库服务器”
--Install =“%cd%\ Derby \ bin \ derby.exe”--Startup = auto
--JavaHome“%cd%\ Java_32_portable ”
--Jvm = “的%CD%\ Java_32_portable \ BIN \客户\的jvm.dll 强>”
--StartMode = Java --StopMode = Java
--StartClass = org.apache.derby.drda.NetworkServerControl --StartParams = start
--StopClass = org.apache.derby.drda.NetworkServerControl --StopParams = shutdown
--Classpath =“%CD%\德比\ lib中\的derby.jar;%CD%\德比\ lib中\ derbyrun.jar;%CD%\德比\ lib中\ derbynet.jar;%CD%\德比\ lib中\ derbytools的.jar“
++ JvmOptions =“的 -Dderby.system.home =%CD%\德比; -Dderby.install.url =%CD%\德比\ lib中; -Dderby.authentication.provider = BUILTIN; -Dderby.storage。 pageCacheSize = 8000; -Dderby.storage.pageSize = 20000; -Dderby.database.sqlAuthorization =假强>“
重要。你应该调整大胆的部分。
最后,您可以使用
检查服务是否开始
net start DerbyService
建议:您可以像我一样将所有内容放在一个bat文件中,您可以在其中定义以前的JAVA_HOME或任何其他必要的变量。