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
my-jar-file-1.0.0-SNAPSHOT-executable.jar
my-jar-file-1.1.0-SNAPSHOT-executable.jar
my-jar-file-1.0.1-SNAPSHOT-executable.jar
should all be executed by the same script.
How can I do this?
-
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.jarMiquel– Miquel2013年03月04日 10:05:02 +00:00Commented Mar 4, 2013 at 10:05
3 Answers 3
If name of jar match pattern my-jar-version.jar:
java -jar `ls my-jar*.jar`
Comments
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.
Comments
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