Skip to content

Instantly share code, notes, and snippets.

@dongjinleekr
Created May 14, 2022 06:37
Show Gist options
  • Save dongjinleekr/8c6a403f30b4207f6fb78bb584b860e7 to your computer and use it in GitHub Desktop.
Save dongjinleekr/8c6a403f30b4207f6fb78bb584b860e7 to your computer and use it in GitHub Desktop.
jshell-on: A simple script for running jshell with dependencies. (just add the following files to your $PATH directory.)
#!/usr/bin/env bash
JSHELL=$(which jshell)
if [[ -z ${JSHELL} ]]; then
echo "jshell not installed; exit."
exit 1
fi
GRADLE=$(which gradle)
if [[ -z ${GRADLE} ]]; then
echo "gradle not installed; exit."
exit 1
fi
JSHEL_GRADLE_SETTINGS=$(dirname $(readlink -f $0))/jshell.gradle
UTILS_SCRIPT=$(dirname $(readlink -f $0))/jshell.jsh
CLASSPATH=$(gradle -b ${JSHEL_GRADLE_SETTINGS} -q printClasspath) ${JSHELL} --start PRINTING --start ${UTILS_SCRIPT}
plugins {
id 'java'
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation 'com.google.guava:guava:27.0.1-jre'
}
task printClasspath {
doLast {
println sourceSets.main.runtimeClasspath.asPath
}
}
// see: https://github.com/openjdk/jdk/blob/3955b037da8a0981d8efc67f28caaacdef7dfb31/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
// see: https://github.com/openjdk/jdk/blob/3955b037da8a0981d8efc67f28caaacdef7dfb31/src/jdk.jshell/share/classes/jdk/jshell/tool/resources/PRINTING.jsh
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
Properties properties(String path) {
Properties prop = new Properties();
try (InputStream input = new FileInputStream(path)) {
prop.load(input);
} catch (IOException ex) {
ex.printStackTrace();
}
return prop;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment