Serverside Java from Chrome and Firefox

Get inside your JVM from the browser with nudge4j

Jane Elizabeth
© Shutterstock / BrAt82

Talk directly to your JVM from inside Chrome, Firefox, or IE11 with nudge4j! This lightweight REPL lets developers to understand their code better and spend less time on debugging or redeploying.

No need for a separate editor with nudge4j! With just a few lines of code, nudge4j allows developers to talk to their Java application within a browser window.

By combining the functionality of Nashorn and HttpServer, nudge4j gives developers the ability to access and change any Java 8 application. Just add a few lines of code to talk to your JVM via the internet, without any need to download a jar, modify a classpath, or alter a pom. And once you’re done, you can just remove the code without any problems.

How it works

Essentially, it’s a read-eval-print-loop (REPL). nudge4j gives developers a simple online page with two elements: an editor and an execute button.

In a typical nudge4j REPL cycle, developers type any code they want to deploy into the editor and press the “Execute on JVM” button. Then, the browser posts the code to your JVM. The JVM runs the code and the result is returned as a string. This is displayed below the button, allowing developers to see exactly how their new code affects the existing JVM.

While the code is sent to the browser in JavaScript, it’s the kind of JavaScript that manipulates Java objects.  Never fear, you don’t actually have to code in JavaScript if you don’t want to – this is taken care of by the built-in JavaScript engine Nashorn.

You can access any Java class that is accessible from your JVM with nudge4j. This means you can call methods, create objects, and more. nudge4j even makes it possible for you to reach more than one object specific to your application for manipulation.

All you really need is Java 8, an internet connection, and an up to date browser like Chrome, Firefox, or IE11.

SEE ALSO: How to use Java 8 streams to swiftly replace elements in a list

Get nudge4j

Want to try out nudge4j for yourself? It only takes adding a few lines of code to your Java application. Just copy and paste the code into your app before you run it and voila.

While it does look even more verbose than the average Java snippet, this is for a couple reasons:

  • It can be dropped into any class, so there are no basic assumptions about imports.
  • The code is wrapped into a function to avoid any clashes with predefined variables.
  • Some IDEs like Eclipse restrict packages with com.sun, so access to the built in JDK HttpServer is done via introspection.

More information can be found on the nudge4j website or on GitHub.

Jane Elizabeth
Jane Elizabeth is an assistant editor for

1 Comment
Inline Feedbacks
View all comments
Java Coder
Java Coder
3 years ago

If I understand that right, in my JAVA application adding those “few lines of code it only takes”:-
– start the nashorn engine
– opens a listener port to may application
– opens access to my application from zeee internets
– digs some additional security holes (“so access to the built in JDK HttpServer is done via introspection”)

What can possibly go wrong?

Sigh, millenials…..