0

I have a bat file I run through command prompt to deploy a java app locally for local testing on my machine:

start java -server -AnotherParameter -AnotherParameter -jar path\to\jar\appName-version.jar
exit

To run this bat file, I use the following command:

start batFileName.bat

However, the next time the version changes on this jar, the bat file will not work, because the version is out of sync. This results in myself having to change my bat file each time the version is updated.

Is there a way to pass in a the version when I run the start command through command prompt to use as the jar name? This way when I run my bat file, I can just pass in the name of the jar at that time to run the java application? If so how would I pass that version into the bat file and how would I use that parameter?

DevelopingDeveloper
  • 883
  • 1
  • 18
  • 41

2 Answers2

1

In your script, replace the version part of the jar file name with an argument replacement parameter:

start java -server -AnotherParameter -AnotherParameter -jar path\to\jar\appName-%1.jar
jwdonahue
  • 6,199
  • 2
  • 21
  • 43
  • In my bat file I have given command : bat " cd location && java -jar appName-%1.jar" but it come up with error unable to find jar appName-%1.jar – Yatin Kanyal Aug 10 '20 at 05:53
0

Do not start the program using java -jar . Change the start up script

  • include the folder where you jar file is present into class path with wild card, like:

    java -cp path\to\jar*

  • call the main class in your jar file. I suppose the main class does not change so often as versions of the jar file? The whole command line will look like this:

    java -cp path\to\jar* com.something.foo.bar.Main

JVM will load your jar whatever its name is, and will find the main class and will start it if it has "main" method.

kachanov
  • 2,696
  • 2
  • 21
  • 16