How to execute console or GUI input as if it was actual Java code?

前端 未结 4 935
眼角桃花
眼角桃花 2021-01-21 08:37

I want to be able to input java commands/code to execute during run-time (during the execution of a \"persistent\" program) in the same way, or as close as possible, to the same

4条回答
  •  失恋的感觉
    2021-01-21 08:56

    Use the JavaCompiler. It can compile code from a String.

    For an E.G. see the STBC & especially the source code. It provides a GUI and can compile the code in the text area on button click.

    STBC GUI

    But note the:

    System Requirements

    STBC will run on any computer with a version 1.6+ Java Plug-In* JDK (AKA SDK).

    (*) The API that STBC uses is merely a public interface to the compiler in the tools.jar that is distributed only with JDKs (though the 'public JRE' of the JDK also seems to acquire a tools.jar). This leads to some unusual requirements in running either the native jar, or the web start app.

提交回复
热议问题