1

I have written a command line tool using picocli and Kotlin. Then I compiled it to an executable uber jar and it actually works as a standalone application by running

java -jar MyJarFile.jar [cli options and parameters]

But how do I bundle it so that I can distribute it on Mac, so that I can run it as

mycommand [cli options and parameters]

I know I can use jpackage, I used it and generated a .pkg file that installed the app on my Mac in the /Applications folder. I guess there is a file that i have to put in a folder that is in the PATH in order to use it as a command line tool. How do I "automate" the process? Is jpackage the right tool?

Wrapping up, what I want to do is to bundle my executable jar so that when the installation process on Mac finishes the user can write

mycommand [cli options and parameters]
Essay97
  • 648
  • 1
  • 9
  • 24
  • With [Packages](http://s.sudre.free.fr/Software/Packages/) you can build a `pkg` with a custom post-installation script – Михаил Нафталь Feb 02 '22 at 12:20
  • your link is not working... and then, what should the postinstall script do? This is my very first macOS app, I don't even know how the whole thing works – Essay97 Feb 02 '22 at 12:35
  • Oops! Here is the correct link: http://s.sudre.free.fr/Software/Packages/about.html With this tool, you may configure the installation path (by the way, jpackage can do this as well via `--install-dir` key) and a post-script should [add it to PATH](https://stackoverflow.com/questions/22465332/setting-path-environment-variable-in-osx-permanently). Alternatively, you may try to install it into a directory which is [in PATH by default](https://stackoverflow.com/questions/9832770/where-is-the-default-terminal-path-located-on-mac) (like `usr/local/bin` for instance), so no post-scripts needed – Михаил Нафталь Feb 02 '22 at 15:51

1 Answers1

0

The picocli documentation has a list of options for packaging your application. (Suggestions for additional options are welcome.)

One of these options that deserves a special mention is creating a native image with GraalVM.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
  • 1
    I ended up creating a formula on Homebrew, but that still depends on the machine having java, so I'll give a try to this! – Essay97 Feb 03 '22 at 23:00