Using Java Types in JavaScript Verticles

171 Views Asked by At

I want to use the class java.util.UUID in a JavaScript Verticle in Vert.x. If I have the code

var classUUID = Java.type("java.util.UUID");

immediately in the script that I start from the command line everything is fine. If I embed the same line of code in a Verticle that I load from my initial script using

container.deployVerticle("verticle.js")

the Verticle seems to get not loaded at all. I don't get an error. But the code is not executed. Has anybody an Idea what's the problem here? Is it a bug in Vert.x? I use Java 8 with Nashorn as the JS-engine. The vert.x version is 2-1-5.

1

There are 1 best solutions below

0
On

I found my error. I have to specify that nashorn is to be used as js-engine by prefixing the name of the file like "nashorn:verticle.js". It seems that this way of referring to Java classes inside JS-code is only possible in nashorn.