0

How can I make a shell script that will execute a jar file, regardless of its version?

Say I have a file:

my-jar-file-1.0.0-SNAPSHOT-executable.jar

I want a shell script that will do something along the lines of

#!/bin/bash
java -some -other -options -jar my-jar-file-1.0.0-SNAPSHOT-executable.jar

But it should execute any version of it, so

  1. my-jar-file-1.0.0-SNAPSHOT-executable.jar

  2. my-jar-file-1.1.0-SNAPSHOT-executable.jar

  3. my-jar-file-1.0.1-SNAPSHOT-executable.jar

should all be executed by the same script.

How can I do this?

subodh
6,15813 gold badges53 silver badges73 bronze badges
asked Mar 4, 2013 at 10:01
1
  • I think you should use soft links. ln -s my-jar-file-1.0.1-SNAPSHOT-executable.jar my-jar-file-1.0.1-executable.jar Commented Mar 4, 2013 at 10:05

3 Answers 3

2

If name of jar match pattern my-jar-version.jar:

java -jar `ls my-jar*.jar`
answered Mar 4, 2013 at 10:09
Sign up to request clarification or add additional context in comments.

Comments

1

We can also think the other way around, why not give a final name to jar, which will remain constant, and no script modifications will be required.

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-jar-plugin</artifactId>
 <version>2.2</version>
 <configuration>
 <finalName>myname</finalName>
 <configuration>
</plugin>

And if having the version number mandatory, you can write a script to pattern search for that particular jar. And run it accordingly.

I did a similar job using ant, but the goal was different, hope this helps.

answered Mar 4, 2013 at 10:09

Comments

1

Try this in a bash script:

for jarfile in my-jar-file-*-SNAPSHOT-executable.jar; do
 java -some -other -options -jar $jarfile
 echo "done for: $jarfile"
done
answered Mar 4, 2013 at 10:14

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.