APPDATA equivalent on macos and linux?

I decided to try this and it works.

I build the app image, i.e, the entire working application which includes the jre.

This is saved to the build folder.

Zip the app image up and distribute it as is.

User can unzip it wherever they want.

I can then do as was mentioned and check location, try writing a file, moving a file, whatever, before running app and display an error message and bail if I cant do that.

The app runs just fine when using the scripts that are in the app image.

This will speed up build time as you don’t have to run jpackage to build the installer, just the app image, which is blazing fast.

Basically just a distZip that takes the hassle out of packaging the jre.

Sorry, I thought you knew. The Tilde notation is an *nix shortcut for “User Home” in a terminal/shell. (Command Line/script environment) Many of the forums that I see tend to use it as slang for “User Home” on any platform, even though it may need to be represented differently in the programming environment they are working with.


Jpackage seems to be assuming that only a system-wide install is acceptable, which is another reason that I probably won’t be looking closer at it…

Its only good for packaging the jre now. As it requires a machine to do that for each os, without github, totally useless.

I’m starting to believe the articles about oracle moving away from java. You cant keep making things harder and expect to attract new users to the language.

When distributing your apps by zip, how do you handle shortcuts for starting your app?

Edit: win, mac, linux

The app that I’m most familiar with deploying uses IZpack.org for Windows and Linux installers.

The windows Install has a ShortcutSpec component that the IZpack runtime can read.

(looks like doing this sort of thing on the command line can be a bit tricky to get right)


The linux install probably doesn’t need IZpack at all, it just runs a set of shell scripts that manipulate XDG desktop and mime definition files, and feeds them the given installation location. Seems to work with pretty much all common linux desktop environments.

The scripts in question are here,

The “Main” script freedesktop-install.sh could easily be modified to grab the current location, if you want installation to just be a matter of un-zipping in place, and running a setup script from there.


Mac does not have an “Installation” process as such. If the user unpacks it into their Applications folder (Which is second nature to most mac users) a properly constructed .app will have metadata that defines any mime/filetype associations. The OS automatically scans and displays such applications in all the standard locations. If the user wants desktop shortcuts, etc. they create them themselves.

Unfortunately this is one of those I had ruled out as its compatible up to java 10 and no releases since 18.

I will test this out to see if jpackage will accept that for the linux build. If it does, that solves two out of three os installs.

Does tilde work for macOs as home?

Doesnt work with tilde.

The jpackage says,

--install-dir <file path>

    Absolute path of the installation directory of the application on OS X or Linux. Relative sub-path of the installation location of the application such as "Program Files" or "AppData" on Windows.

So how can you give an absolute path to home dir when you dont know user?

On linux/mac how do you write paths to those or some standard directory where its common to expect write permissions are set?

You don’t. jpackage seems to be trying for a system-wide installation. This would typically mean /Applications (Note the lack of tilde, as this is an absolute path. On *nix-y systems, all things accessible through the file system are on a path descended from the ‘root’ / instead of from one of several drive letters, as in the windows world.) The problem with installing there is that it’s probably going to need Admin permissions to do the download/updating thing. Which it seems you would like to avoid.

For Mac:

  • Don’t try for the application package step
  • Stop with the application image (The one that is a nested set of folders that starts with MyApp.app at the top)
  • If you don’t have Xcode tools, you will not be able to sign the .app. Warn your users that they may need to allow third-party apps in their security settings.
  • Zip that entire directory tree. (Or, If You’re feeling adventurous, find a windows tool that can pack it into a .dmg)
  • Mac user opens that up, and manually moves the .app directory (and it’s contents, but most users think that it’s a single file) to wherever they want it.
  • If you need a space to keep settings, downloaded assets, etc. use System.getProperty("user.home") internally
  • If you only need to work on parts of the app in-place, that’s when you use the code snippet I included up-thread.

IZpack is still under development, (last commit 5 days ago) but we’ve never included a JRE. (On my list to consider for future)

Yes, but you’d only be using it that way if you are trying to create a shell script. (OSX is basically a customized Unix system, so the shell languages are largely cross-compatible. Our dev/beta builds are just a zipped folder with no packaging. The Linux launch script works on macs, too.)

I see, thanks for the extra info.

The only reason I want definite install locations is I want to stay away from relative paths for deleting and moving. I don’t want to screw up someones system. Which is very easily done if an relative path is used in conjunction with Files.walkFileTree.

With windows, I can fully control the paths as the key variable is from the environment.

System.getenv("LOCALAPPDATA")

This makes things easy and safe, at least I feel its safer.

user.home would be just as good but I guess I will have to wait for that one.

On Linux systems you can do this to get the value of the HOME variable:

System.getenv("HOME");

Edit: It looks like the HOME environment variable is also present on macOS: macOS Environment variables - macOS - SS64.com

Except you cannot use that with jpackage.

You cannot install anywhere you have write access as near I can tell with anything other than windows.

If there is a way on mac and linux, please let me know. I can’t find anything that says how to do it.

I just thought that you could use System.getenv() since you gave that example with LOCALAPPDATA on Windows. Anyway, you can use the HOME environment variable to feed the install-dir parameter on jpackage.

I will test that and report back.

1 Like

Wait, how do you pass that variable as an argument so the installer users it?

Edit: Wont the installer use the computer used to build the install package path, not the users path, is what I am asking

Oh, man… you’re right. It worked on my tests because I have the same user name on both computers. My bad.

I would normally at this point ask for this to be a feature added to the installer but I found that only authorized oracle people can do that.

You have to have an account and I couldn’t find any way to get one.

Is there any absolute path, common to all linux and macs, with write privlages .etc, that can be fed into the installer?

Even if it requires the user to give permissions to install, where they could manually set permissions so the app would not need to ask for permissions again after they are set by the user?

I could just give instructions in that case on how to set the permissions.

Unfortunately, I dont have linux os or mac so I can figure this stuff out.

Can’t you just go with .tar.gz or similar? And then maybe write a shell script to ask the users where they want it to be extracted?
I mean, the jpackage tool as it is now won’t work as we all would like it to work.

I already set gradle up so I have the option to just tar.gz and distribute.

I looked at writing scripts just to set a desktop shortcut and found something you would think was simple as that required an enormous amount of knowledge and was dangerous as hell if not done correctly.

I don’t know enough about scripts to do it properly and at this stage I am thinking I will most likely concentrate on windows and if things work out, worry about other systems later.

The biggest problem for me is that I want to control exactly where the app is installed. Just like every other app that writes to disk on my windows system does. They don’t give the option of where to install things that need to be updated.