简体   繁体   English

从控制台运行和作为服务运行时,Java Service Wrapper出现问题

[英]Trouble with Java Service Wrapper when run from console vs. run as a service

I've got a Java Service Wrapper application that accesses registry entries. 我有一个访问注册表项的Java Service Wrapper应用程序。 (Yeah, I know, weird, huh? In case you're wondering, I'm using David's solution to this question to read from the registry using Java.) (是的,我知道,很奇怪,是吧?如果您想知道的话,我正在使用David的解决方案来使用Java从注册表中读取该问题 。)

Everything works just fine on 32-bit versions of Windows. 在Windows的32位版本上,一切正常。 I can run my application from both the console (using the Java Service Wrapper's .bat file) and as a service installed from the bat file. 我可以从控制台(使用Java Service Wrapper的.bat文件)运行应用程序,也可以从bat文件安装该服务。 I can see the various things I need from the Windows registry. 我可以从Windows注册表中看到所需的各种信息。

However, on a 64-bit Windows system, I can no longer see the registry entries I need when I run the application as a service; 但是,在64位Windows系统上,将应用程序作为服务运行时,我不再看到所需的注册表项。 the entries all appear to be null. 所有条目似乎都为空。 However, it still works in the console! 但是,它仍然可以在控制台中使用!

My hypothesis is that when run from the console (as an administrative user, in case it's relevant) the Java Service Wrapper starts a 64-bit JVM and is able to access the regular 64-bit registry. 我的假设是,当从控制台运行时(作为管理员,如果需要的话),Java Service Wrapper将启动64位JVM,并能够访问常规的64位注册表。 Then, when run as a service (via the LOCALSYSTEM user) it starts a 32-bit JVM (which would then try to access the oh-so-special 32-bit registry in the Wow6432bit node. The entries I'm looking for are absent from this node, which would then explain why I get null values for them in this case. 然后,当作为服务运行(通过LOCALSYSTEM用户)时,它将启动32位JVM(然后它将尝试访问Wow6432bit节点中的“如此特殊的32位”注册表。我正在寻找的条目是这个节点不存在,这将解释为什么在这种情况下为什么我得到空值。

This leads to my question: why on Earth would the Java Service Wrapper start a 32-bit JVM when started via the services list, and why would it start a 64-bit JVM when started from the console? 这引出了我的问题:为什么地球上的Java Service Wrapper通过服务列表启动时会启动32位JVM,为什么从控制台启动时会启动64位JVM?

NOTE: I'm using Java Service Wrapper 3.5.14 and in my config file I have 注意:我正在使用Java Service Wrapper 3.5.14,在我的配置文件中

wrapper.java.additional.auto_bits=TRUE

Ideally, I'd like to keep the JVM selection automatic, so I can use one installer to deploy my software on both 32-bit and 64-bit systems. 理想情况下,我希望自动选择JVM,因此我可以使用一个安装程序在32位和64位系统上部署我的软件。 (This is one reason I chose to use JSW over Tomcat, in fact.) (实际上,这是我选择在Tomcat上使用JSW的原因之一。)

Thanks so much for reading. 非常感谢您的阅读。

It turns out that my installer (which I was using to install and start the service) is a 32-bit application, which causes the Java Service Wrapper .bat files to run in a 32-bit environment during the install process. 事实证明,我的安装程序(我用来安装和启动服务)是一个32位应用程序,它导致Java Service Wrapper .bat文件在安装过程中在32位环境中运行。 Since there's no 32-bit Java on the 64-bit system, this means that the wrapper can't find Java. 由于64位系统上没有32位Java,这意味着包装器找不到Java。

The trick (which I learned from the helpful folks at Tanuki Software's support) is to tell the .bat file to run the 64-bit wrapper if it's known that we're running in a 32-bit environment on a 64-bit system. 诀窍(我从Tanuki Software的支持人员那里学到的)是,如果已知我们在64位系统上的32位环境中运行,则告诉.bat文件运行64位包装器。

Basically, in the .bat file, find these lines and insert the indicated line. 基本上,在.bat文件中,找到这些行并插入指示的行。 If I encounter further problems, I'll update my answer. 如果遇到其他问题,我将更新答案。 But for now, this solution seems to work well for me quite nicely. 但就目前而言,该解决方案似乎对我来说很好。

rem
rem Decide on the specific Wrapper binary to use (See delta-pack)
rem
if "%PROCESSOR_ARCHITEW6432%"=="AMD64" goto amd64 (<---- insert this line)
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto amd64
if "%PROCESSOR_ARCHITECTURE%"=="IA64" goto ia64

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM