Skip to content

Hot reload? #2091

Closed
Closed

Description

@aghasemi

Hi. A few question and a possible feature request, if not already present.

  1. Is it possible to figure out in the code if it is being run in JBang?
  2. If yes, is it possible to get the full path of the Java file that is being executed?
  3. 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?
  4. Actually, is there a "hot reload" mechanism available already for JBang?

Thanks a lot

Activity

  1. added
    ideasSome idea/suggestion around jbang behavior/feature set
    on Jul 4, 2025
  2. quintesse commented on Jul 4, 2025

    @quintesse
    Contributor
    1. 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).

    1. 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.

    1. 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?
    2. 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)

    HTH

  3. maxandersen commented on Jul 5, 2025

    @maxandersen
    Collaborator

    @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 :)

  4. locked and limited conversation to collaborators on Jul 5, 2025
  5. converted this issue into a discussion #2096 on Jul 5, 2025
  6. added theissue type on Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideasSome idea/suggestion around jbang behavior/feature set

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions