I am seeing different behavior between Windows, Ubuntu, and Manjaro when creating files. Windows and Manjaro correctly are creating files in the relative path of the jar. However, Ubuntu seems to be creating the files at the user.home
location instead.
File file = new File("file.ext");
The files are being created a couple different ways...
// 1 Normal
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {}
// 2 ImageIO
BufferedImage bufferedImage = ImageIO.read(new URL(imageUrl));
imgFile.createNewFile();
ImageIO.write(bufferedImage, "jpg", imgFile);
// 3 Log4J
<RollingFile name="RollingFile" fileName="./log/output-${date:yyyyMMdd}.log" filePattern="./log/output-%d{yyyyMMdd}.log">
// 4 Sqlite
Connection sqlite = DriverManager.getConnection(String.format("jdbc:sqlite:%s", dbFileName));
All of these files are ending up in the user home in Ubuntu. I've tried the path name plain file.ext
and ./file.ext
but neither works.
Additional system details:
Ubuntu Desktop 20.04
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-bo1-6ubuntu2~20.04-bo1)
OpenIDK 64-Bit Server VM (build 25.265-bo1, mixed mode)
EDIT:
It seems that this happens when running the jar from double click after making it executable chmod +x myproject.jar
. It seems that running the jar via terminal java -jar myproject.jar
the files appear in the relative path beside the jar.
Something about the executable/double click is causing them to appear in the user.home