Yes, it’s possible to execute Java from our Javascript controllers. It’s not possible to put a shebang (#!) like you put on top here, but it’s done in a different way…
Right now it’s no documentation for this, but will be added very soon. In the mean time you can look at some “libs” that we have created here: https://github.com/enonic/xp
Thanks for that, very useful. Should definitively be included in the docs
I ended up using Java.type() to get the Java-stuff I needed instead.
For you other people reading this (maybe you are a noob on Nashorn like myself), it was as simple as:
var HttpClient = Java.type('org.apache.commons.httpclient.HttpClient');
var GetMethod = Java.type('org.apache.commons.httpclient.methods.GetMethod');
var httpclient = new HttpClient();
var method = new GetMethod("http://www.example.com");
var statusCode = httpclient.executeMethod(method);
var responseBody = method.getResponseBodyAsString();
The classpath had to be included in build.gradle:
dependencies {
include "commons-httpclient:commons-httpclient:3.1"
}