Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

command to run latest java jar in a directory

Tags:

shell

I'm currently running my jars with $ java -jar /path/to/fooproject-x.y.z-standalone.jar where x.y.z is the version. I could've sworn I saw a very simple, slightly modified version of this command that just runs the highest version jar in the directory and I can't for the life of me find it again. This is a real thing right?

like image 237
deadghost Avatar asked Jun 28 '26 07:06

deadghost


1 Answers

Please consider this command:

$ ls *.jar | sort -t- -k2 -V -r | head -1

I'm specifying the separator and set of keys to sort on. And use pipe to find the latest JAR with head command. You can assign this way:

LATEST_VERSION=$(ls foo*.jar | sort -t- -k2 -V -r | head -1)

And run the jar with any params you need.

like image 156
dimirsen Z Avatar answered Jun 29 '26 19:06

dimirsen Z



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!