gpt4 book ai didi

java - 我的 jar 可以在 Ubuntu 上运行,但不能在 Windows 上运行

转载 作者:行者123 更新时间:2023-12-01 18:15:20 25 4
gpt4 key购买 nike

我已经在 NetBeans 中创建了一个 Java 项目,自动构建的分发文件 (.jar) 在我的 Ubuntu 15.04 AMD64 计算机上运行得非常好。

我想在分发它之前确保它在 Windows 上运行,但在 Windows 7 32 位机器上进行测试后,我发现它不起作用。下面是错误消息的屏幕截图。

The error shown on windows terminal

我可以猜测一些问题 - 因为它讨论了 .regex 错误。我实际上并没有在代码中使用 regex,而是使用 String.split,我认为它调用了 regex 包 - 这是在 FileHandler 类的构造函数中。所以看起来这是一个问题。

您可以在 GitHub 上查看完整代码:

https://github.com/samredway/PwStore/tree/master/src/com/redway_soft/pwstore

目标机器上的Java版本是:1.8.0_45与我的构建机器上的情况相同。

非常感谢任何帮助。

编辑导致问题的特定部分似乎是我的 FileHandler 类的构造函数。看起来像这样:

public FileHandler() {       

String path = this.getClass().getProtectionDomain().getCodeSource()
.getLocation().toString().substring(5);

String[] arry_path = path.split(File.separator);

path = "";
for (int i = 0, j = arry_path.length - 1; i < j; i++) {
path += arry_path[i] + File.separator;
}

PASSWORDS = path + "data" + File.separator + "passwords.sec";

}

最佳答案

这行似乎是你的问题。

String[] arry_path = path.split(File.separator);

Windows 上的文件分隔符与 Ubuntu 等 Unix 操作系统上的文件分隔符不同。

Windows 中使用的文件分隔符是 \,它是正则表达式中的特殊字符,需要转义才能进行正则表达式编译。

正如 nneonneo 所指出的下面,可以通过将该行更改为轻松解决此问题:

String[] arry_path = path.split(Pattern.quote(File.separator));

关于java - 我的 jar 可以在 Ubuntu 上运行,但不能在 Windows 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30003057/

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