0

I'm working on an existing java desktop application. I've got the application creating an installer using the new jpackage tool but need to create some application specific data files on the target desktop computer which could be apple, windows or linux.

Is there a recommended standard you are aware of for placing such application specific files? Similar in concept to where firefox or chrome creates their cache files. These files would not be manipulated by the user other than through the application.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Tony
  • 31
  • 4
  • If these data files are read-only, then just have them as standard Java resources. If you need to write to these data files, then you'll have to choose a "known location" on the host computer. The easiest solution, and one that a lot of cross-platform applications use, is create an application-specific directory in the user's home directory. You can get the user home directory via `System.getProperty("user.home")`. The other option is to try and detect what platform you're on (you might be able to do this statically, since you know the target platform when invoking `jpackage`), and then... – Slaw Aug 11 '22 at 05:34
  • ...use that platform's "preferred" location. On Windows, that might be the "app data" directory, local or otherwise. I'm not familiar enough with MacOS or Linux to know where user applications should store their data. And finally, if you only need these data files for one instance of the application, then just use temporary directories/files (Java provides APIs for creating temporary files). Ideally, you'd also clean up these temporary files when the application exits. – Slaw Aug 11 '22 at 05:37
  • Thanks Slaw, the files need to be writeable, they are sqllite db files. To get the application working I've already done what you've suggested with the use of System.getProperty("user.home"). Now that I'm looking to deploy, I'm looking for known conventions. – Tony Aug 11 '22 at 06:11
  • As I mentioned, using the user's home directory (more specifically, an application-specific directory _in_ the user's home directory) is a pretty well used "convention". But I also mentioned you can try to detect the OS and then use an OS-specific location (you'll have to research each OS for this). On Windows, this would probably be `%APPDATA%` or `%LOCALAPPDATA%` (which are environment variables). – Slaw Aug 11 '22 at 06:14
  • This should help: [Deploy a writable properties file in jpackaged Java application](https://stackoverflow.com/questions/71518577/deploy-a-writable-properties-file-in-jpackaged-java-application) – DuncG Mar 23 '23 at 10:45

0 Answers0