Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 9 REPL for running app

Java 9 is introducing REPL called JShell inside the JDK distribution. Is there any way to connect into the JShell of the JDK that is running some application and execute commands referencing that running app. For example executing some methods form the apps code, inspecting objects, etc..?

like image 911
Saša Šijak Avatar asked Jun 23 '16 10:06

Saša Šijak


1 Answers

JShell is not the standard java command, it's another command. Once you open the shell it "goes" in Read Eval Print Loop. Once you type a command it's read and parsed by the shell, evaluated and the result is printed.

You can define variables and add classes to the classpath, but I don't think is possible starting an application or a server from there, at least not at this stage and not in the same JVM. As you can add classes you can instantiate them, but you don't have an option to inspect their variables. However you can see the variables you instantiate in your JShell scope (what objects you created, you can access and print only their their public methods and variables).

It seems JShell will have an api, which opens the way for other possibilities.

like image 65
adiian Avatar answered Nov 15 '22 17:11

adiian