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

标签 java file-exists java-service-wrapper

我有以下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 2008 Java 版本: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/

相关文章:

raspberry-pi - Raspberry PI 上的 Java 服务包装器

Java:如何在 C:\drive 中创建文件

java - OSGi 基于角色的安全性

java - 读取巨大文件中的行组

java - 用于在 Java 中 pretty-print 时间段的库,仅提供最重要的字段

c - 在C语言中使用套接字创建服务器和客户端应用程序检查文件

java - Java 服务包装器的 JVM 错误

来自 Maven 的 Java Service Wrapper 类路径排序

Python - 如何在 Ubuntu 上的根文件夹中打开或创建文件?

javascript 使用 google map api 检查文件是否存在