gpt4 book ai didi

java - 默认目录必须是绝对目录

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:33:24 24 4
gpt4 key购买 nike

我的代码调用了 log4j 包中的方法:

org.apache.log4j.PropertyConfigurator.configure("log4j.properties")

在Windows系统和Linux虚拟机上运行都没有问题。但是,在公司提供的Linux虚拟机上运行时,出现如下错误,如下图所示:

enter image description here

我从哪里开始解决它?

补充:这是我的代码:

public static void main(String[] args) {
PropertyConfigurator.configure(configDir + File.separator + "log4j.properties");
if(log.isDebugEnabled()) {
log.debug("load complete:" + configDir + File.separator + "log4j.properties");
}
}

第一行执行报错,错误为:

Exception in thread "main" java.lang.ExceptionInInitializerError
...
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:315)
at com.dcits.provider.BaffleProvider.main(BaffleProvider.java:29)
Caused by: java.lang.RuntimeException: default directory must be absolute
...

最佳答案

当用户目录系统属性(即 "user.dir")不是绝对路径时,无法构建默认文件系统。

在 Windows 和 AIX 上使用 Java 8 执行此代码会生成运行时异常,类似于原始海报所见。

public class RelativeUserDir
{
public static void main(String[] args)
{
// Set the "user.dir" property to the "current directory" relative path
System.setProperty("user.dir", ".");

FileSystems.getDefault();
}
}


window :

Exception in thread "main" java.lang.AssertionError: Default directory is not an absolute path
at sun.nio.fs.WindowsFileSystem.<init>(WindowsFileSystem.java:61)
at sun.nio.fs.WindowsFileSystemProvider.<init>(WindowsFileSystemProvider.java:53)
at sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:36)
at java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:108)
at java.nio.file.FileSystems$DefaultFileSystemHolder.access$000(FileSystems.java:89)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:98)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:96)
at java.security.AccessController.doPrivileged(Native Method)
at java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:96)
at java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:90)
at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
at RelativeUserDir.main(RelativeUserDir.java:12)


AIX:

Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.ensureError(J9VMInternals.java:146)
at java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:135)
at java.nio.file.FileSystems.getDefault(FileSystems.java:187)
at RelativeUserDir.main(RelativeUserDir.java:10)
Caused by: java.lang.RuntimeException: default directory must be absolute
at sun.nio.fs.UnixFileSystem.<init>(UnixFileSystem.java:67)
at sun.nio.fs.AixFileSystem.<init>(AixFileSystem.java:55)
at sun.nio.fs.AixFileSystemProvider.newFileSystem(AixFileSystemProvider.java:62)
at sun.nio.fs.AixFileSystemProvider.newFileSystem(AixFileSystemProvider.java:55)
at sun.nio.fs.UnixFileSystemProvider.<init>(UnixFileSystemProvider.java:68)
at sun.nio.fs.AixFileSystemProvider.<init>(AixFileSystemProvider.java:57)
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1773)
at sun.nio.fs.DefaultFileSystemProvider.createProvider(DefaultFileSystemProvider.java:60)
at sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:78)
at java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:119)
at java.nio.file.FileSystems$DefaultFileSystemHolder.access$000(FileSystems.java:100)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:109)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:107)
at java.security.AccessController.doPrivileged(AccessController.java:638)
at java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:107)
at java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:101)
... 2 more

关于java - 默认目录必须是绝对目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53774782/

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