Command to run latest java jar in directory
I am currently running my jars with $ java -jar /path/to/fooproject-x.y.z-standalone.jar
, where x.y.z
is version. I could swear that I saw a very simple, slightly modified version of this command that launches the highest jar version in the directory and I can't have life find me again. It's true?
+3
source to share
1 answer
Please consider this command:
$ ls * .jar | sort -t- -k2 -V -r | head -1
I set a separator and a set of keys to sort. And use a pipe to find the latest JAR with the head command . You can assign this way:
LATEST_VERSION = $ (ls foo * .jar | sort -t- -k2 -V -r | head -1)
And run the jar with whatever parameters you need.
+1
source to share