You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. A few question and a possible feature request, if not already present.
Is it possible to figure out in the code if it is being run in JBang?
If yes, is it possible to get the full path of the Java file that is being executed?
If yes and yes, is it possible to use these information to implement a "hot reload" mechansim, i.e. kill and restart the script whenever a change in the file is detected?
Actually, is there a "hot reload" mechanism available already for JBang?
Is it possible to figure out in the code if it is being run in JBang?
Code isn't actually being run "in" JBang. Once the code is running JBang is gone, it's only used to start the code. But you can test that JBang was used to start the code by testing for certain environment variables, like for example JBANG_LAUNCH_CMD (which is the path of the JBang command used to run the code).
If yes, is it possible to get the full path of the Java file that is being executed?
From within your running code? Not without knowing what was passed to JBang in the first place. So if you ran jbang SOMETHING you can also run jbang info tools SOMETHING and that will give you a lot of information.
If yes and yes, is it possible to use these information to implement a "hot reload" mechansim, i.e. kill and restart the script whenever a change in the file is detected?
Actually, is there a "hot reload" mechanism available already for JBang?
Well, as explained in the first point, JBang is actually not present anymore when your code is running so a hot reload mechanism doesn't seem possible given the current system.
But people do use JBang scripts together with Quarkus which does have a hot reload mechanism, perhaps that is an option?
(You can do jbang init -t qcli for example code using Quarkus, see jbang template list for other templates using Quarkus)
@quintesse 's reply is 100% correct. you can detect if jbang was used to run ( or rather that the jbang wrapper script was used to run ); once that is done jbang is not in control - the java or whatever is used to run is in control - jbang does not have a superpower it is Just Java :)
Activity
quintesse commentedon Jul 4, 2025
Code isn't actually being run "in" JBang. Once the code is running JBang is gone, it's only used to start the code. But you can test that JBang was used to start the code by testing for certain environment variables, like for example
JBANG_LAUNCH_CMD(which is the path of the JBang command used to run the code).From within your running code? Not without knowing what was passed to JBang in the first place. So if you ran
jbang SOMETHINGyou can also runjbang info tools SOMETHINGand that will give you a lot of information.Well, as explained in the first point, JBang is actually not present anymore when your code is running so a hot reload mechanism doesn't seem possible given the current system.
But people do use JBang scripts together with Quarkus which does have a hot reload mechanism, perhaps that is an option?
(You can do
jbang init -t qclifor example code using Quarkus, seejbang template listfor other templates using Quarkus)HTH
maxandersen commentedon Jul 5, 2025
@quintesse 's reply is 100% correct. you can detect if jbang was used to run ( or rather that the jbang wrapper script was used to run ); once that is done jbang is not in control - the java or whatever is used to run is in control - jbang does not have a superpower it is Just Java :)