Reputation: 8127
I have created a Java project in NetBeans and the automatically built distribution file (.jar) runs absolutely fine on my Ubuntu 15.04 AMD64 machine.
I wanted to make sure it runs on windows before I distribute it, but having tested on a windows 7 32 bit machine I found it doesn't work. Below is a screen shot of the error message.
I can guess at some issues - in that it talks about a .regex error. I don't really use regex in my code but use String.split which I think calls on the regex package - that is in my constructor for the FileHandler class. So it looks like that is an issue.
You can see the full code here on GitHub :
https://github.com/samredway/PwStore/tree/master/src/com/redway_soft/pwstore
The Java version on the target machine is: 1.8.0_45 As is the same on my build machine.
Any help much much appreciated.
EDIT the specific section causing the problem seems to be the constructor for my FileHandler class. Which looks like this:
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";
}
Upvotes: 0
Views: 433
Reputation: 560
This line seems to be your problem.
String[] arry_path = path.split(File.separator);
The file separator on Windows is different from that on a Unix operating system like Ubuntu.
The file separator used in Windows is \
which is a special character in regex and needs to be escaped for the regex to compile.
As pointed out by nneonneo below, this can easily be remedied by changing the line into:
String[] arry_path = path.split(Pattern.quote(File.separator));
Upvotes: 2
Reputation: 179422
You are doing
path.split(File.separator)
and on Windows the separator is \
which is not a valid regex.
Per https://stackoverflow.com/a/2736278/1204143, try using
path.split(Pattern.quote(File.separator))
instead.
Upvotes: 2