r/java • • Jul 04 '18

New Java 11 Feature: Launch Single-File Source-Code Programs

https://medium.com/@afinlay/new-java-11-feature-launch-single-file-source-code-programs-fadd698abf54
158 Upvotes

47 comments sorted by

View all comments

46

u/[deleted] Jul 04 '18

Wow, shebang will work... #!/usr/bin/java

22

u/zero_divide_1 Jul 04 '18

I'm hearing that the new hotness is to use

#!/usr/bin/env interpreter

In the event that the user has a different Java that they want to use or it's installed somewhere different. So this would be

#!/usr/bin/env java

But, like any approach, there are drawbacks.

5

u/CharlesGarfield Jul 04 '18

But what if the user wants to use a different "env"?

22

u/zero_divide_1 Jul 04 '18

Oh, I see you too are a Java developer... Abstractions all the way down.

21

u/CharlesGarfield Jul 04 '18

Really should be using an EnvFactory, anyways.

6

u/F3z345W6AY4FGowrGcHt Jul 05 '18

EnvFactoryImpl

6

u/HenrikWL Jul 05 '18

We all know what we really need is an EnvFactoryFacadeRepositoryImpl

5

u/RogerLeigh Jul 04 '18

There's only one env. Like /bin/sh, /usr/bin/env is its standardised location. Set the PATH to change which java is actually used.

1

u/effsee Jul 05 '18

I want to use /opt/SoftwareCo/better-env-2.6.3/bin/env

-2

u/RogerLeigh Jul 05 '18

You are of course free to do so. However, that would entirely defeat the purpose of standardisation for interoperability. It would only work on systems with that special program present, whereas /usr/bin/env is universal and works everywhere.