EDIT: I’m not sure if this is the right category, feel free to move it if you want.
The problem
So, since Sponge came, i had a lot of ideas for plugins. One of them is a plugin for scripting in Javascript, along with some Node-like features.
To program this plugin, i needed a decent Javascript engine. I had two choices:
- Use Javas builtin Javascript engine (via JSR-XXX), based on Mozilla Rhino, or
2 Use the ‘standalone’ Rhino, which has a bit better performance than the builtin one.
So, it was a logical decision to go for the standalone Rhino. However, the Rhino project was started in 1997, and lacks a lot of performance.
Recently, Oracle released a wonderful project, called Nashorn. Nashorn is a very fast Javascript engine, included in Java 8. For people who want to use Javascript in their Java program, this is a good option.
However, since Minecraft and Sponge, and most Java users nowadays, are not running on Java 8, but on Java 7, or even Java 6, it is not an option to use Nashorn.
The solution
After some research, i found a Nashorn backport (by ramonza) to Java 7. This was excellent! I forked the project, and i am running it on GitHub. You can easily build it using Gradle and add it to your project as an external library, or if you’re using Git, you can add the project as a submodule. And voilá, you are running Nashorn on Java 7.
I made some changes/additions to Nashorn:
- Switch from Ant to Gradle (for easier building)
Since there are some people interested in a Javascript engine, i decided to publish and share it. The repo can be found here.
A more extensive tutorial is available here.
The project is by far not finished, so feel free to contribute, look at it, throw potatoes at it if you feel like, or test it.
BTW:
The only downside i can find on Nashorn is that the startup is very slow. However, it’s blazingly fast after a warming-up.