问题
I have an application that launches a jar file. However, the jar has the version number in the name and will change every few months. I'm looking to write this so I don't have to update the application's code every time the jar is changed. I've tried using * for a wildcard, but I get:
Error: Unable to access jarfile C:\Selenium\vendor\selenium-server-standalone-\*.jar
The command I'm running is:
java -jar C:\\Selenium\\vendor\\selenium-server-standalone-*.jar
When I put in the version number, the jar launches successfully. Is there anyway to use a wildcard here?
回答1:
Not sure about windows, the best you can do here is to write a minimal batch file that greps the file name and puts it right there
for unix: you could do something like
java -jar *.jar
this works well in unix
回答2:
I think a very simple way of doing this, and have it working in Windows and Unix is by setting an environment variable with the version you want to execute, and just like Jigar says, create a simple batch file that executes the correct version.
So if you set
$VERSION=1.0 and
$JARPATH = C:\\Selenium\\vendor
you could easily make a batch file that does
java -jar $JARPATH\\selenium-server-standalone-$VERSION.jar
You can then have many versions of the JAR file, in the same directory, and just by changing the variable you can execute the version you want.
来源:https://stackoverflow.com/questions/21589278/execute-a-jar-with-wildcard-in-path