Return to site

☕ JAVA TRICK: Executing Source Files as Scripts

December 22, 2021

You know that you can use the'ðĢ𝐚ðŊ𝐚' command to launch a single source file without having to manually compile it first,

but did you know that you can use this capability to write full-on scripts in Java in just three simple steps?

First , add a shebang line to the source file that points at your 'ðĢ𝐚ðŊ𝐚' executable, followed by '--𝐎ðĻðŪðŦ𝐜𝐞' and the Java version the code was written for:

#!/𝑐/𝑃𝑟𝑜𝑔𝑟𝑎~1/ð―ð‘Žð‘Ģ𝑎/𝑗𝑑𝑘-17/𝑏𝑖𝑛/𝑗𝑎ð‘Ģ𝑎 --𝑠𝑜ð‘Ē𝑟𝑐𝑒 17

Second, rename the file so it doesn't end with '.ðĢ𝐚ðŊ𝐚' extension - this is a great opportunity to gite it a good command-liney name.

Third make it executable with "ðœðĄðĶðĻ𝐝 +ðą".

There you go, script in Java!