gpt4 book ai didi

java - 使用 javaservice.exe File.exists() 返回 false

转载 作者:行者123 更新时间:2023-12-01 10:33:33 28 4
gpt4 key购买 nike

我有以下Java代码来检查远程目录是否存在:“\\server_web\\Covers”

File CoversPathFile = new File(Options.CoversPath);
if (!CoversPathFile.getAbsoluteFile().exists()) throw new Exception();

通过命令行或 .Bat 文件执行时效果很好,但如果我使用 JavaService.exe要将 java 类包装在 Windows 服务中,File.exists() 方法返回 false;

如果使用本地路径,则不会出现此问题。

这是 JavaService.exe 错误吗?

JavaService.exe版本:2.0.10.0平台:Windows 2008Java 版本:8.0_40

最佳答案

您必须指定当前工作目录。因为您使用的是相对路径名。从批处理开始使起始路径成为当前工作路径。因此,您可以使用 -current 选项来提供路径:

-current current_dir (optional) - A directory to use as the current working directory for the service. If this parameter is specified, all relative paths in the service will be relative to relative to the specified directory.

另请参见此处:

http://javaservice.ow2.org/docs/devdocs/devcmds.html

<小时/>

更新:

如果您正在访问远程资源,则分配给该服务的用户没有访问该资源的权限。

要更改权限,您必须为您的服务分配特定用户。默认情况下,服务在本地服务用户帐户上运行。将其更改为正确的用户。

打开服务并更改注册“登录”上的用户。

或者使用 javaservice.exe 中的选项 -user:

-user user_name (optional) - Specify the Windows domain username to be used when running the service (also requires that the password parameter is specified). Local user accounts are specified as .\user_name whereas domain accounts may be specified as either domain\user_name or user_name@domain (the latter form has been required on some systems to avoid reports of 'I/O Operation in progress' errors).

我强烈建议阅读上面的链接。

关于java - 使用 javaservice.exe File.exists() 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34952515/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com