MacOS – Using “Jar Launcher” on High Sierra how to pass command line arguments to a java app (jar)

javamacos

Is it possible to use "Jar Launcher" on Mac to pass command line arguments to a java app? For example:

open myApp.jar –args -hello

This ought to run myApp and pass it "-hello" but it doesn't.

I'm on High Sierra 10.13.6. This comes with a "Jar Launcher". It's /System/Libary/CoreServices/Jar\ Launcher.app.

I can run the jar file with Jar Launcher, I did it from Finder and it works, but without command line arguments. After that I can run a command line "open myApp.jar" and that works too, the open command uses Jar Launcher to open it. So far so good.

Now I want to pass arguments, let's say "-hello"

I tried "open myApp.jar –args -hello". That does not work, the application does not receive the hello argument.

I can't figure out how to do this. Maybe the problem is with "Jar Launcher", maybe it won't pass arguments through to the java app?

I know this can be done by installing a full JDK and using the java command instead of the built-in Jar Launcher, or compiling my jar into a Mac executable. I'm not a developer, I'd like to know if I can achieve this just using what's shipped on my Mac.

Earlier versions of MacOs shipped with a more complete Java environment, and a lot of the help I find out there refers to earlier versions.

Best Answer

try creating a sh or command file where the jar file exists, eg myj.command. Then make edit with chmod7 755 so its executable in console.

the myj should be java -jar .jar --