I am deploying a command-line tool that is written in Java that accepts command-line arguments. I have it packaged as a JAR file because it is convenient to have a single file.
The problem is that to run it you must first call java -jar (filename) (args)
and that is quite annoying.
The current way I have it is to have a simple bash script that launches it, but this is less than ideal.
Is there anyway (in Linux, Ubuntu Server) to make a JAR file that invokes the Java VM by itself? I've looked for a shebang, but couldn't find one (which of course makes sense since it is compiled code).
This is what I want to do: myprogram.jar arg1 -arg2
instead of this: java -jar myprogram.jar arg1 -arg2
Thanks,
Brian
On debian based distribution, it is possible to install jarwrapper
I think that this is possible to do the same thing on other distributions by installing with the same package name.
The .zip file format (upon which the .jar format is based) seems to be robust in the presence of extra data prepended to the file. Thus if you use the
cat
command to put a shebang before the zip data in the jar file, and make the file executable, then you can call the jar file like you would call any ordinary shell script.For example: (Note that the
unzip -l
command is just to illustrate the point. It doesn't change anything about the .jar and can be omitted when you're actually doing this process.)See Documentation/java.txt in the Linux Kernel documentation, which tells you how to configure a system using the
binfmt_misc
kernel module to run Jar files automatically. However, this is a configuration option you change on a computer, not something you change about the jar file, so it doesn't follow the jar file from system to system.