1

How create a batch file to a jar file that contains a SortFile.java class that is responsible for sorting the content of a file. This class is taking 2 arguments the first one is sort and the second is file name. I would like to create a batch file that will be moved to cmd and after the path to this batch file user can pass those 2 args. The .jar let's say is on C:\dir\SortFile.jar and I would like to execute this batch from any location. Could someone help me, I never wrote a batch files that executes jars. I google it, but all examples I found did not explain it as well, there was no example for that case I need it.

Reddi
  • 677
  • 6
  • 19

1 Answers1

1

Let's go step by step:

The .jar let's say is on C:\dir\SortFile.jar

So your batch file probably should contain java -jar C:\dir\SortFile.jar sort fileToSort (assuming of course that you compiled that Java code already, and that you build the JAR file so that it can be called that way)

I would like to execute this batch from any location.

Then that batch file should be located somewhere in your %PATH%.

If you prefer to use the CLASSPATH, see here for guidance.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
GhostCat
  • 137,827
  • 25
  • 176
  • 248