1

I want to be able to execute this code:

java -jar myJar.jar arg0 arg1

as:

program arg0 arg1

I'm on Windows and was only able to find how to do it on Linux (which I don't have and can't understand anyway).

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
J. Doe
  • 27
  • 1
  • 3
  • 2
    What do you mean by *single command*? `java` **is** a single command – Jacob G. Mar 22 '19 at 21:18
  • @JacobG.I don't want to write "java -jar myJar.jar". I want to write just "program". So basically a single word with no spaces in between. – J. Doe Mar 22 '19 at 21:20
  • May I ask why you want to do that? This seems like an [XY Problem](http://xyproblem.info/). – Jacob G. Mar 22 '19 at 21:21
  • @JacobG. It's for a CLI and I don't want the user to be writing a long command every time he needs to execute a command. For example: "java -jar myJar.jar -help" , I believe is way too long for just a simple help command and I want it to look like "program -help" – J. Doe Mar 22 '19 at 21:31
  • 1
    https://stackoverflow.com/questions/54956072/can-i-create-shorthand-names-for-use-inside-cmd – Noodles Mar 22 '19 at 21:34

1 Answers1

1

You can write a custom bash script that executes your jar.

With "$@" you can forward all arguments passed to the bash script to your jar.

java -jar <your-jar> "$@"

Execute it like that:

script.bat arg1 arg2 arg3

Glains
  • 2,773
  • 3
  • 16
  • 30