Shebang Mechanism Support in IntelliJ IDEA 2020.3
The upcoming IntelliJ IDEA 2020.3 will support the shebang mechanism to run single-file programs directly from source. This enhancement to the Java launcher was delivered in JDK version 11.
The idea of the shebang mechanism is to reduce packaging overhead and simply run the program.
To execute the file with the operating system’s shebang mechanism, its first line should start with #!.
Here’s how to make it work in IntelliJ IDEA:
- Create a simple file without an extension. IntelliJ IDEA can now postpone the file type detection, which was not possible in previous versions. Note that the file may be placed inside or outside of the source root.
- After the shebang character sequence (#!) define the path to the JDK. You can use the –source option to specify the source version of the source code or the default version of the platform will be used. Other parameters like classpath can be defined as well.
- Enter the source code starting from the second line
- The resulting file should be made executable: you can use the chmod +x filename command in the Terminal to execute it as a program.
Now the file is ready to use. IntelliJ IDEA will highlight it as a common Java file. Code completion, inspections, code generation, and refactoring all work here as well.
Try the new features coming in IntelliJ IDEA 2020.3 for free through our EAP program!
Subscribe to Blog updates
Thanks, we've got you!
IntelliJ IDEA 2023.3 Is Out!
IntelliJ IDEA 2023.3 has arrived! This blog post lists all of the notable updates delivered in the new version.
New Livestream – Enhance Code Safety: Unveiling IntelliJ IDEA’s New Exploitable Path Feature
Join us for the new IntelliJ IDEA LiveStream episode with Ori Bendet and Yaroslav Russkih to learn about secure coding within IntelliJ IDEA.
Java Annotated Monthly – December 2023
The December edition of Java Annotated Monthly is here! As usual, you’ll find all the latest Java and Kotlin updates as well as details of key industry events for networking and learning. This issue also features the latest release candidates and targeted JEPs alongside Java tutorials and articles a…
IntelliJ IDEA 2023.3 Release Candidate Is Out
IntelliJ IDEA 2023.3 Release Candidate is now available! You can get the latest build from our website, through the free Toolbox App, or via snaps for Ubuntu. To use this build, you need to have an active subscription to IntelliJ IDEA Ultimate. Download IntelliJ IDEA 2023.3 RC As we …