Code Monkey home page Code Monkey logo

springboot-jshell-adapter's Introduction

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.

springboot-jshell-adapter's People

Contributors

toparvion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.