{"id":15494891,"url":"https://github.com/fracpete/jshell-scripting","last_synced_at":"2025-04-22T20:25:35.038Z","repository":{"id":57719807,"uuid":"139288807","full_name":"fracpete/jshell-scripting","owner":"fracpete","description":"Java widget for scripting with jshell. Requires Java 9 or later.","archived":false,"fork":false,"pushed_at":"2024-01-07T22:54:24.000Z","size":120,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T12:15:45.480Z","etag":null,"topics":["java","jshell","scripting","swing"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fracpete.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-01T00:10:01.000Z","updated_at":"2024-02-04T22:39:34.000Z","dependencies_parsed_at":"2024-12-10T14:48:38.514Z","dependency_job_id":null,"html_url":"https://github.com/fracpete/jshell-scripting","commit_stats":{"total_commits":42,"total_committers":3,"mean_commits":14.0,"dds":0.04761904761904767,"last_synced_commit":"831e9608efd007d6782f2db2f11e257f2cbf888b"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fracpete%2Fjshell-scripting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fracpete%2Fjshell-scripting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fracpete%2Fjshell-scripting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fracpete%2Fjshell-scripting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fracpete","download_url":"https://codeload.github.com/fracpete/jshell-scripting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250317297,"owners_count":21410717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jshell","scripting","swing"],"created_at":"2024-10-02T08:15:31.735Z","updated_at":"2025-04-22T20:25:35.020Z","avatar_url":"https://github.com/fracpete.png","language":"Java","readme":"# jshell-scripting\n\nJava widget for scripting with [jshell](https://docs.oracle.com/javase/9/jshell/). \nRequires Java 9 or later, as it relies on the `jshell` executable in Java's `bin` \ndirectory.\n\nThe widget comes in form of a panel with two parts, the scripting part for your code \n(including syntax highlighting thanks to [RSyntaxTextArea](http://bobbylight.github.io/RSyntaxTextArea/))\nand the output part, which will receive any output generated by `jshell`.\n\nWith this widget you can write Java code without having to compile it, `jshell`\ntakes care of that.\n\n\n## Usage\n\n### Java GUI\n\nYou only have to place the `JShellPanel` in a frame or dialog and you\ncan start scripting (see example [GUI.java](src/main/java/com/github/fracpete/jshell/examples/GUI.java)).\n\n```java\nimport javax.swing.JFrame;\nimport com.github.fracpete.jshell.JShellPanel;\n...\nJShellPanel panel = new JShellPanel();\nJFrame frame = new JFrame(\"JShell\");\nframe.getContentPane().setLayout(new BorderLayout());\nframe.getContentPane().add(panel, BorderLayout.CENTER);\nframe.setSize(1200, 900);\nframe.setDefaultCloseOperation(BaseFrame.EXIT_ON_CLOSE);\nframe.setLocationRelativeTo(null);\nframe.setVisible(true);\n```\n\nIt is also possible to listen to events in the widget, by supplying a\n`com.github.fracpete.jshell.event.JShellPanelListener` object. For listening to \nexecution events, supply a `com.github.fracpete.jshell.event.JShellExecListener` \nobject. The following code simply outputs the event types to stdout (see \nexample [GUIEvents.java](src/main/java/com/github/fracpete/jshell/examples/GUIEvents.java)):\n\n```java\nimport com.github.fracpete.jshell.event.JShellExecEvent;\nimport com.github.fracpete.jshell.event.JShellExecListener;\nimport com.github.fracpete.jshell.event.JShellPanelEvent;\nimport com.github.fracpete.jshell.event.JShellPanelListener;\nimport com.github.fracpete.jshell.JShellPanel;\n...\nJShellPanel panel = new JShellPanel();\npanel.addJShellExecListener((JShellExecEvent e) -\u003e System.out.println(\"exec: \" + e.getType()));\npanel.addJShellPanelListener((JShellPanelEvent e) -\u003e System.out.println(\"panel: \" + e.getType()));\n```\n\nThere are several themes available:\n* dark\n* default\n* default-alt\n* eclipse\n* idea\n* monokai\n* vs\n\nWhich you can get/set via the following methods of the `JShellPanel` class:\n* `getCurrentTheme()`\n* `setCurrentTheme(String)`\n\n### Java backend\n\nYou can also execute code in the background using the `JShellExec` class\n(see example [Exec.java](src/main/java/com/github/fracpete/jshell/examples/Exec.java)):\n\n```java\nimport com.github.fracpete.jshell.JShellExec;\n...\nString code = \"for (int i = 0; i \u003c 10; i++) System.out.println(i)\";\nJShellExec exec = new JShellExec();\nexec.runScript(code);\n```\n\nIf you want to react to error messages, simply add a `com.github.fracpete.jshell.event.JShellErrorListener` listener:\n\n```java\nimport com.github.fracpete.jshell.JShellExec;\nimport com.github.fracpete.jshell.event.JShellErrorListener;\n...\nString code = \"for (int i = 0; i \u003c 10; i++) System.out.println(j)\";\nJShellExec exec = new JShellExec();\nexec.addJShellErrorListener(new JShellErrorListener() {\n  public void jshellErrorOccurred(JShellErrorEvent e) {\n    System.err.println(e.getMessage());\n    if (e.hasException())\n      e.getException().printStackTrace();\n  }\n});\nexec.runScript(code);\n```\n\nJust like with `JShellPanel`, you can add listeners for events to the execution\n(e.g., that the execution has finished) by supplying a \n`com.github.fracpete.jshell.event.JShellExecListener` instance. The following \ncode just outputs the event types to stdout (see example [ExecEvents.java](src/main/java/com/github/fracpete/jshell/examples/ExecEvents.java)): \n\n```java\nimport com.github.fracpete.jshell.JShellExec;\n...\nString code = \"for (int i = 0; i \u003c 10; i++) System.out.println(i)\";\nJShellExec exec = new JShellExec();\nexec.addJShellExecListener((JShellExecEvent e) -\u003e System.out.println(\"exec: \" + e.getType()));\nexec.runScript(code);\n```\n\n### Additional flags\n\n`JShellPanel` and `JShellExec` both support JShell's additional flags: \n\n* `-J` - runtime flags, used by JShell itself, e.g., `-verbose`\n* `-R` - remote runtime flags, the JVM that executes the code, e.g., `-javaagent:some.jar`\n* `-C` - compiler flags\n\nIn case of `JShellPanel`, you can supply/access these flags via the following methods:\n* `setRuntimeFlags(List\u003cString\u003e)/getRuntimeFlags()`\n* `setRemoteRuntimeFlags(List\u003cString\u003e)/getRemoteRuntimeFlags()`\n* `setCompilerFlags(List\u003cString\u003e)/getCompilerFlags()`\n\nIn case of `JShellExec`, these flags have to be supplied to the `runScript` method.\n\n\n### Command-line\n\nYou don't have to use the widget in your own code, you can simply go ahead\nand do some scripting. Here is what you need to do:\n\n* download a release zip file and unzip it\n* place any additional jars that you want to use for coding in the `lib` directory\n* start up the user interface with the appropriate script:\n\n    * Linux/OSX: `bin/jshell.sh`\n    * Windows: `bin\\jshell.bat`\n\n* start scripting\n\n\n## Releases\n\n* [0.1.2](https://github.com/fracpete/jshell-scripting/releases/download/jshell-scripting-0.1.2/jshell-scripting-0.1.2-bin.zip)\n* [0.1.1](https://github.com/fracpete/jshell-scripting/releases/download/jshell-scripting-0.1.1/jshell-scripting-0.1.1-bin.zip)\n* [0.1.0](https://github.com/fracpete/jshell-scripting/releases/download/jshell-scripting-0.1.0/jshell-scripting-0.1.0-bin.zip)\n* [0.0.4](https://github.com/fracpete/jshell-scripting/releases/download/jshell-scripting-0.0.4/jshell-scripting-0.0.4-bin.zip)\n* [0.0.3](https://github.com/fracpete/jshell-scripting/releases/download/jshell-scripting-0.0.3/jshell-scripting-0.0.3-bin.zip)\n* [0.0.2](https://github.com/fracpete/jshell-scripting/releases/download/jshell-scripting-0.0.2/jshell-scripting-0.0.2-bin.zip)\n* [0.0.1](https://github.com/fracpete/jshell-scripting/releases/download/jshell-scripting-0.0.1/jshell-scripting-0.0.1-bin.zip)\n\n\n## Maven\n\nAdd the following dependency to your `pom.xml`:\n\n```xml\n    \u003cdependency\u003e\n      \u003cgroupId\u003ecom.github.fracpete\u003c/groupId\u003e\n      \u003cartifactId\u003ejshell-scripting\u003c/artifactId\u003e\n      \u003cversion\u003e0.1.2\u003c/version\u003e\n    \u003c/dependency\u003e\n```\n\n## Screenshots\n\nDefault theme:\n\n![Screenshot of example script output](src/site/resources/example.png)\n\nDark theme:\n\n![Screenshot of example script output](src/site/resources/example_dark.png)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffracpete%2Fjshell-scripting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffracpete%2Fjshell-scripting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffracpete%2Fjshell-scripting/lists"}