Вы можете изменить свой user.dir. Сначала я думаю, что это «неприкасаемый».
Итак, сначала нужно сделать его "осязаемым"
Мы вызываем следующее, используя статический блок для нашего класса MainWindow
static {
try {
Class clazz = ClassLoader.class;
Field field = clazz.getDeclaredField("sys_paths");
boolean accessible = field.isAccessible();
if (!accessible) {
field.setAccessible(true);
}
field.set(clazz, null);
try {
String currentDir = System.getProperty("java.library.path");
//now remove the current directory from the library path.
String sansCurrentDir = removeCurrentDirectoryFromPath(currentDir);
System.setProperty("java.library.path", sansCurrentDir );
}
finally {
field.setAccessible(accessible);
}
} catch (Exception e) {
//in our case we rethrow
}
}
//and then later in our code in the same static block we can now create our root directory (ie, the user.dir) and execute
System.setProperty("user.dir", rootDirectory);