user6044627
user6044627

Reputation: 100

java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/ScriptUtils in osgi bundle

ScriptEngineManager manager = new ScriptEngineManager(null);
ScriptEngine engine = manager.getEngineByName("nashorn");
BundleContext context = FrameworkUtil.getBundle(FormulaImpl.class).getBundleContext();
URL configURL = context.getBundle().getEntry("eval.txt");
if (configURL != null) {
    InputStream input = null;
    try {
        input = configURL.openStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        StringBuilder out = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            out.append(line);
        }
        engine.eval(out.toString());
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    } finally {
        try {
            input.close();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}

Object obj = engine.get("formulaColumn");

In this code, obj is getting as object array. I can not convert into object. In java 1.7 using Rhino object is getting. I tried with

Object obj = (Object)ScriptUtils.convert(engine.get("formulaColumn"), Object.class);

But No calssDef error showing in java 1.8

I am using osgi. I exported jdk.nashorn.api.scripting.ScriptUtils . From my jsfile i am returning an array.

Upvotes: 2

Views: 1241

Answers (1)

Shemeem
Shemeem

Reputation: 198

I think you don't have to use ScriptUtils.convert() method in your java code, if you are returning your data from java script as follows:

return Java.to(data,"java.lang.Object")

I hope, this would be helpful.

Upvotes: 2

Related Questions