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?
In Java, we can use the following code snippets to get the path of a running JAR file. // static String jarPath = ClassName. class . getProtectionDomain() .
In general, to include all of the JARs in a given directory, you can use the wildcard * (not *. jar ). The wildcard only matches JARs, not class files; to get all classes in a directory, just end the classpath entry at the directory name.
To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar. We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …]
To check our CLASSPATH on Windows we can open a command prompt and type echo %CLASSPATH%. To check it on a Mac you need to open a terminal and type echo $CLASSPATH.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With