X

Geertjan's Blog

  • September 7, 2016

Finegrained JShell Integration in NetBeans IDE

Geertjan Wielenga
Product Manager

In addition to the generic JShell integration in NetBeans, discussed yesterday, there's more finegrained support enabling project-specific JShell snippets to be run. That means, depending on how you organize your life, no "build" will be needed anymore when you try out your code. Just hack a snippet together, run it in JShell, when/if it works, move it to your project.

Each project, whether Maven-based or Ant-based, will have an "Execute Java Shell" menu item, which is shown below. When that menu item is clicked, a new VM is created, which has access to the project's path, including project-specific JShell snippets, as discussed below.

Below you see a folder "nbproject/private/jshell-snippets", which contains JShell snippets that I know will be handy for experimenting with in the context of my project:

Also, note that there's a folder called "startup", within "jshell-snippets", above. Anything in there will be executed automatically when the project-specific JShell starts up. In the case of Maven, you'll set a property in your POM, "org.netbeans.jshell.snippetsRoot", which points to a folder in which your snippets, including the optional "startup" folder, are found:

<org.netbeans.jshell.snippetsRoot>src/jshell-snippets</org.netbeans.jshell.snippetsRoot>

Once the project-specific JShell has started either via a Maven project or an Ant project, there's a small drop-down that shows an item for each of the JShell snippets, which can be run by clicking on them:

Alternatively, you can do a Run/Debug project and then Run | Open Java Shell for Main Project, which connects to the VM where the project is run/debugged. The difference is the startup procedure. "Execute Java Shell" only starts the machine and waits for interaction from JShell, while "Open Java Shell" works with an existing process which starts as a regular application.

Join the discussion

Comments ( 2 )
  • guest Thursday, September 8, 2016

    Wow, great!

    Can I run this in NB 8.x?


  • Naoki Kishida Friday, September 9, 2016

    When can we try this functionality?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services