Easily Merge Multiple Java --classpath Arguments

twitter logo github logo ・1 min read

I always confuse myself as to whether the correct flags for java and the jshell are -cp or --classpath or --class-path or something else, so instead of trying to remember something like a normal human, I instead spent a few hours pulling this script together.

It automatically detects any variation of cp, classpath, and class-path flags in a series of command-line arguments, and concatenates all of the correct arguments to give you a nice, clean classpath. I hope it's useful!

twitter logo DISCUSS (2)
markdown guide
 

An alternative to the for loop is the while loop with the shift command. It is without indexes and much simpler.

BTW: This script look like in Java. Bash is not Java, Bash is different. Use echo for return values from function.

 

Hi Vlastimil. I used indices because I need the i-th argument and also the i+1-th argument at the same time. shift throws away earlier arguments. There might be a way to refactor it, which I would love to see.

I use exit codes to indicate the status of the method -- i.e. 0 if everything went fine, 1 if there was an error, etc. I also use echo to print strings meant to be "returned" from the functions. See above!

Classic DEV Post from Aug 24 '17

JavaScript Is Eating The World

NodeJS is quickly becoming one of the most commonly used language in building web applications and is beginning to find its way into the Enterprise.

Andrew profile image
Got a Ph.D. looking for dark matter, but not finding any. Now I code full-time. Je parle un peu français. He/Him. dogs > cats

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️