Toparvion / springboot-jshell-adapter

A simple script for running JShell against Spring Boot packaged classpath

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SpringBoot JShell Adapter

A simple script to launch JShell against Spring Boot packaged classpath.

The script can be useful to quickly prototype on non-development environments (like Docker containers) where environment difference matters (e.g. OS features, file system structure, network policy restrictions, etc).

Usage

Deploy

  1. Make sure you have Java 11+ installed on target environment

  2. Copy jshellw wrapper script into destination, e.g.

$ sudo docker cp jshellw mycontainer:/microservice/jshellw
  1. Make the script executable
$ sudo docker exec -w /microservice mycontainer chmod +x jshellw
  1. Run the script pointing to Spring Boot JAR or WAR archive
$ sudo docker exec -it -w /microservice mycontainer ./jshellw app.jar

The output should look like:

Created temp directory '/tmp/...'. Extracting classpath content...
Extracted 191 files from the archive to '/tmp/.../BOOT-INF'.
Starting JShell with '/usr/lib/jvm/java-11-openjdk-amd64/bin/jshell --feedback verbose --class-path /tmp/.../BOOT-INF/classes:/tmp/.../BOOT-INF/lib/*'...
|  Welcome to JShell -- Version 11.0.1
|  For an introduction type: /help intro

jshell>
In case of Windows

To run the script in Windows just execute the following instead of steps 2 and 3:

java --source 11 jshellw app.jar

Check

To check if classpath has been composed and applied correctly, type /env and you should see something like:

jshell> /env
|     --class-path /tmp/.../BOOT-INF/classes:/tmp/.../BOOT-INF/lib/HdrHistogram-2.1.9.jar:...<other-jars>...

Play

Now you can import any classes from your classpath and work with them in JShell just like you do in your dev environment.
For example:

jshell> import org.springframework.util.StringUtils
jshell> var cleanedPath = StringUtils.cleanPath(".\\..\\core/inst/meg.dump")
cleanedPath ==> "../core/inst/meg.dump"
|  created variable cleanedPath : String

You can even launch the application at whole by invoking it's main class, e.g.

jshell> import com.example.spring.boot.application.MainClass
jshell> MainClass.main(new String[0])

but before it make sure that current value of user.dir system property points to application's home directory (if it matters).

Need help on using JShell?

See this Comprehensive Guide or google for java repl.

About

A simple script for running JShell against Spring Boot packaged classpath

License:MIT License


Languages

Language:Java 100.0%