Question

Is it possible to execute a jar file by simply typing the jar name into the command line? Is there anything I can add to the manifest to achieve this?

Ie. jarname.jar instead of java -jar jarname.jar

Was it helpful?

Solution

You can't really avoid that easily.

A common strategy is to deploy an executable startup script with your application; one per platform since this is platform specific (e.g. an executable shell script for Linux, and a batch script for Windows). Standard shell scripting techniques can be used to pass command line parameters to the script on to your application.

Note that there are some clever platform-specific tricks, such as the Linux one here (and I'm not certain but it may be possible to make all jars executable on the command line with some dirty registry hacks on Windows); but if you are going for platform-independence (and you don't want to have to post-process your JARs after a build), deploying a wrapper script is the way to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top