Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a Jar with Wildcard in Path

Tags:

java

jar

selenium

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?

like image 887
Andrew Avatar asked Feb 05 '14 21:02

Andrew


People also ask

How do I run a path from a JAR file?

In Java, we can use the following code snippets to get the path of a running JAR file. // static String jarPath = ClassName. class . getProtectionDomain() .

How do I include all JARs in a folder CLASSPATH?

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.

How do I run a specific class in a jar?

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 …]

How do I find the CLASSPATH of a JAR file?

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.


1 Answers

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

like image 163
jmj Avatar answered Sep 17 '22 09:09

jmj