Search code examples
rhinonashorn

Can't import net.sf.json with Nashorn


I'm upgrading my vm to java 8 and so i'm migrating rhino to nashorn. In my old script i several use importPackage(net.sf.json);

Following https://wiki.openjdk.java.net/display/Nashorn/Rhino+Migration+Guide i've used Java.type and JavaImporter but i get "net" as null


Solution

  • "net" package prefix is not defined in Nashorn global scope. You can workaround by evaluating this:

    var net = Packages.net;