jshell

How to execute java jshell command as inline from shell or windows commandLine

爷,独闯天下 提交于 2019-12-21 06:41:05
问题 Are there any way to execute java command on REPL ( jshell ) as inline command without launching it? E.g. Perl inline command $perl -e 'printf("%06d", 19)' 000019 I have to launch jshell to run any command: $jshell | Welcome to JShell -- Version 9 | For an introduction type: /help intro jshell> String.format("%06d", 19) $1 ==> "000019" I found similar question here, but it's not feasible solution to create a separate jsh file for individual command. Another solution on same post is: echo "1+2

How to run a JShell File?

拈花ヽ惹草 提交于 2019-12-19 16:12:40
问题 I'd like to run an entire file with JShell like: $ jshell my-jshell-skript.java Where e.g. the content of my my-jshell-skript.java is 40 + 2; . Or alternatively an executable like: #!/usr/bin/jshell 40 + 2 Is this possible now or do I still have to take the old way over a Java-Main-Class? Edit 1: Windows-Problem On Windows, there is still no solution for me: C:\JDKs\jdk9.0.0.0_x64\bin>type foo.jsh 1 + 1 C:\JDKs\jdk9.0.0.0_x64\bin>jshell.exe foo.jsh | Welcome to JShell -- Version 9 | For an

How to run a java application with jshell?

本小妞迷上赌 提交于 2019-12-19 09:42:08
问题 How to run a java application with jshell? It should be able to specify classpath and call java command and pass some arguments like bash does,e.g, #!/bin/bash $ARGS=... $CLASSPATH=... java -cp $CLASSPATH $ARGS com.example.MyApp Update: I think a wrapper of Runtime or Process is required, e.g., jshell> private String executeCommand(String command) { ...> ...> StringBuffer output = new StringBuffer(); ...> ...> Process p; ...> try { ...> p = Runtime.getRuntime().exec(command); ...> p.waitFor()

JShell access to variables defined outside of jshell instance

无人久伴 提交于 2019-12-19 02:49:07
问题 From inside jShell script, is it possible to access or register variables that are defined in code that's also creating JShell? Currently there seems to be no mechanism to either access or register a variable to Shell instance, or return none string types from inside JShell (like objects or lambda etc.) ex: import jdk.jshell.JShell; import jdk.jshell.JShellException; import jdk.jshell.SnippetEvent; import java.util.List; public class Main { public static void main(String[] args) throws

How to import a custom class in intellij JShell console

♀尐吖头ヾ 提交于 2019-12-19 00:41:41
问题 I am using the new intellij Jshell console (introduced here https://blog.jetbrains.com/idea/2017/09/java-9-and-intellij-idea/) I created a simple class file Test2.java public class Test2 { public static String test(){ return "Hello"; } } The JShell console is able to find the method in the hints when i try to run this on intellij jshell console (Tools>Jshell Console) Test2.test(); I get the following error "C:\Program Files\Java\jdk-9.0.1\bin\java" --add-modules java.xml.bind -classpath "C:

How to import a custom class in intellij JShell console

可紊 提交于 2019-12-19 00:41:27
问题 I am using the new intellij Jshell console (introduced here https://blog.jetbrains.com/idea/2017/09/java-9-and-intellij-idea/) I created a simple class file Test2.java public class Test2 { public static String test(){ return "Hello"; } } The JShell console is able to find the method in the hints when i try to run this on intellij jshell console (Tools>Jshell Console) Test2.test(); I get the following error "C:\Program Files\Java\jdk-9.0.1\bin\java" --add-modules java.xml.bind -classpath "C:

final variables are not functioning well in jshell

好久不见. 提交于 2019-12-18 05:02:23
问题 I am working with jshell of JDK9. I just created a final variable and assigned a value to it. And in the next line i just modified the value. And to my surprise, there was no error when modifying the final variables. Here is the code snippets: jshell> final int r = 0; | Warning: | Modifier 'final' not permitted in top-level declarations, ignored | final int r = 0; | ^---^ r ==> 0 jshell> r = 1; r ==> 1 jshell> System.out.println("r = "+r) r = 1 Is it what is expected from jshell? or there is

final variables are not functioning well in jshell

与世无争的帅哥 提交于 2019-12-18 05:01:02
问题 I am working with jshell of JDK9. I just created a final variable and assigned a value to it. And in the next line i just modified the value. And to my surprise, there was no error when modifying the final variables. Here is the code snippets: jshell> final int r = 0; | Warning: | Modifier 'final' not permitted in top-level declarations, ignored | final int r = 0; | ^---^ r ==> 0 jshell> r = 1; r ==> 1 jshell> System.out.println("r = "+r) r = 1 Is it what is expected from jshell? or there is

In JShell, how to import classpath from a Maven project

核能气质少年 提交于 2019-12-17 15:51:39
问题 I have a local Maven project under development. How can I launch jshell with the project class path with all the dependencies, so that I can test project or dependency classes inside JShell. 回答1: You can use the jshell-maven-plugin: mvn com.github.johnpoth:jshell-maven-plugin:1.1:run which will fire up a JShell session with your project's runtime path. If you want to include your test dependencies just add -DtestClasspath to the command. Source code: https://github.com/johnpoth/jshell-maven

Disable JShell history

别来无恙 提交于 2019-12-14 03:45:39
问题 JShell by default enables a persistent history of everything typed, which can be recalled by pressing the up arrow. Where is the setting to turn this ❝feature❞ off? Also, how do I even clear the current history? Maybe I'm dumb but I can't figure out the command. /reset seems to do nothing. 回答1: Also, how do I even clear the current history? What I'm proposing is clearly a hack but it seems to be working, at least in Windows 10 with JDK11.0.4: Run Registry Editor and search for the ' /J/Shell