将 Java 应用程序作为 Windows 服务启动时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26838517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 10:44:19  来源:igfitidea点击:

Error in starting java application as windows services

javawindows-services

提问by user3797438

I have downloaded commom-daemon tool and used with a java application. I have created a bat file as shown below

我已经下载了 commom-daemon 工具并与 java 应用程序一起使用。我创建了一个bat文件,如下所示

set SERVICE_NAME=sample
set PR_INSTALL=D:\commons-daemon-1.0.15-bin-windows-signed\prunsrv.exe

REM Service log configuration
set PR_LOGPREFIX=%SERVICE_NAME%
set PR_LOGPATH=D:\logs
set PR_STDOUTPUT=D:\logs\stdout.txt
set PR_STDERROR=D:\logs\stderr.txt
set PR_LOGLEVEL=Error

REM Path to java installation
set PR_JVM=C:\Java\jre7\bin\client\jvm.dll
set PR_CLASSPATH=D:\commons-daemon-1.0.15-bin-windows-signed\Daemon.jar

REM Startup configuration
set PR_STARTUP=auto
set PR_STARTMODE=jvm
set PR_STARTCLASS=com.SomeService
set PR_STARTMETHOD=start

REM Shutdown configuration
set PR_STOPMODE=jvm
set PR_STOPCLASS=com.SomeService
set PR_STOPMETHOD=stop

REM JVM configuration
set PR_JVMMS=256
set PR_JVMMX=1024
set PR_JVMSS=4000
set PR_JVMOPTIONS=-Duser.language=DE;-Duser.region=de

In cmd , I install the service using the command

在 cmd 中,我使用命令安装服务

prunsrv.exe //IS//sample

After this, a service named sample become available in the list of services and when I tried to start it it shows:

此后,名为 sample 的服务在服务列表中可用,当我尝试启动它时,它显示:

Windows could not start the sample on Local Computer. For more information review the System event log. If this is a non-Microsoft service, contact the service vendor and refer to the server specific

error code 1

Windows 无法在本地计算机上启动示例。有关详细信息,请查看系统事件日志。如果这是一项非 Microsoft 服务,请联系服务供应商并参考特定于服务器的信息

错误代码 1

UPDATEDWhen I run

当我跑步时更新

prunsrv.exe //ES//sample

it shows

表明

The data area passed to a system call is too small.
Failed to start service

Can any one help me in this?

任何人都可以帮助我吗?

回答by OscarSan

I had the same problem. In my case (not yours exactly), the problem was the jvm.dll path, because the variable %JAVA_HOME% has spaces. So to solve this, I modify the assignment

我有同样的问题。在我的情况下(不完全是你的),问题是 jvm.dll 路径,因为变量 %JAVA_HOME% 有空格。所以为了解决这个问题,我修改了分配

set CG_PATH_TO_JVM=%JAVA_HOME%\jre\bin\server\jvm.dll

to

set CG_PATH_TO_JVM="%JAVA_HOME%\jre\bin\server\jvm.dll"

and that's all.

就这样。

Also, you could check the variables assignment with this command:

此外,您可以使用以下命令检查变量分配:

prunmgr//ES//yourservicename_as_in_windows

回答by hb3

To help others troubleshooting.

帮助他人排除故障。

If you look at: https://commons.apache.org/proper/commons-daemon/procrun.html

如果您查看:https: //commons.apache.org/proper/commons-daemon/procrun.html

There is a parameter:

有一个参数:

--LogPath

which defaults to:

默认为:

%SystemRoot%\System32\LogFiles\Apache

A log file is generated there which contains some additional error messages and possibly useful information. The original questioner changed the log path to:

在那里生成一个日志文件,其中包含一些额外的错误消息和可能有用的信息。原发问者将日志路径改为:

set PR_LOGPATH=D:\logs

So looking there would be the appropriate thing to do in their case.

因此,在他们的情况下,寻找合适的做法是可行的。

回答by etoricky

I agreed with OscarSan that a space in %JAVA_HOME% could cause the "error code 1" problem. I solve this problem by re-installing JDK 1.8 to change the installation path from C:\Program Files Java\jdk1.8.0_144to C:\Java\jdk1.8.0_144. Problem solved.

我同意 OscarSan 的意见,即 %JAVA_HOME% 中的空格可能会导致“错误代码 1”问题。我通过重新安装 JDK 1.8 将安装路径从C:\Program Files Java\jdk1.8.0_144 更改C:\Java\jdk1.8.0_144来解决这个问题。问题解决了。

回答by Casey

I also had this cryptic error message 'The data area passed to a system call is too small.' with no further information in either the startup log or the Windows/System32/LogFiles/Apache/ logs on Win 8/Server 2008.

我也有这个神秘的错误消息“传递给系统调用的数据区域太小。” 在启动日志或 Win 8/Server 2008 上的 Windows/System32/LogFiles/Apache/ 日志中没有更多信息。

I had renamed my packages and the --StartClass and --StopClass parameters were wrong.

我重命名了我的包,并且 --StartClass 和 --StopClass 参数是错误的。