1

I am running one jdk command in window batch file as:

javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -jar C:\Users\sampleJAR\myProj-1.0.0.jar

But, every 2 weeks we will have new version coming up and old jar will be replaced by new jar automatically so I was thinking to use wildcard with something like:

javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -jar C:\Users\sampleJAR\myProj-*.jar

I referred lots of articles online which suggested to use *, surround jar name with "" when using *,... None of them worked.

James Z
  • 12,209
  • 10
  • 24
  • 44
Jeetendra Ahuja
  • 177
  • 2
  • 17
  • 2
    just write a batch file or bash script which searches for the latest version – Michael Jul 10 '18 at 15:21
  • Actually, there is one other script which will backup old jar to some other directory and we will always have only one jar in "target" directory but it's name will keep changing with suffix of latest version. @Michael – Jeetendra Ahuja Jul 10 '18 at 15:29
  • See [this superuser answer](https://superuser.com/a/460609/545384) for an explanation (tl;dr : wildcard expansion is up to the application) – Aaron Jul 10 '18 at 15:29
  • Yeah, it looks like Windows cmd.exe doesn't support wildcard expansion but I am able to do `dir sam*` in command prompt though. Thanks @Aaron – Jeetendra Ahuja Jul 10 '18 at 15:45

1 Answers1

6

I believe that the articles you are looking at are in reference to the classpath option wildcard expansion.

The -jar option doesn't do this wildcard expansion and expects a filename without any wildcards.

You could try specifying the classpath with the wildcard and then putting the class name that you want to run at the end of the command. Hopefully like:

javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -cp "C:\Users\sampleJAR\*" com.my.classname

timl
  • 131
  • 5
  • Thanks for reply @timl , I tried something like: `javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -cp C:\Users\Work\Projects\target\adapter-* com.full.package.name.Adapter` to run my jar but it didn't work, is it what you suggested? In this case, jar name is `adapter-1.0.0.jar` and the class which has main method is `Adapter.class` – Jeetendra Ahuja Jul 10 '18 at 18:43
  • Did you try something more similar to the second suggestion. I was just able to run this `java -cp "C:\path\to\jar\*" com.my.class` – timl Jul 10 '18 at 19:49