Can Java 9 jshell be used to run code in another JVM?

Java 9 has a read-eval-print loop for Java called jshell . I saw how it works in native mode, from the command line. Can it also be used in a remote process? In other words, can I connect to another Java process and enter code snippets to run within this runtime? This would be a good way to change the configuration state on the application server without having to write an administration tool using the user interface.

+8
java java-9 jshell
source share
3 answers

The simple answer is no, there is no way to bind jshell to a running Java process. jshell is a standalone application running in its own JVM.

+4
source share

There is no official way to do this.

However, it is not difficult to rebuild the code and run it on another virtual machine through a Java agent. This, however, will not work as well as you expect, since it is unclear which class the loader should use the shell and how it should interact with the running program.

+5
source share

Answer qaru.site/questions/724785 / ... includes hacked decision and the proposal, which could be the cleanest solution.

Part of another answer, assuming that JShell runs code only in its virtual machine, is incorrect - JShell runs a separate JVM with transport via JDI by default (at least on Linux). But yes, I don’t know the official way to do this.

0
source share

All Articles