Search code examples
javascriptjavanashorn

Where do I set the environment parameters while calling custom java classes from nashorn script


//Custom Java class
package com.xxx.yyyyyy.summary.Entry;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Summarize {
}

This is the class file and this cannot be referenced from Nashorn Script

And JavaScript jjs response

var MyJavaClass = Java.type('com.xxx.yyyyyy.summary.Entry.Summarize');

This does NOT work

var MyJavaClass = Java.type('java.lang.Boolean');

This works fine

This is related to some class path - so where to add it?


Solution

  • jjs supports -classpath option and you've to specify classpath for your application classes that are accessed from javascript.

    See also : https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jjs.html