wanted to try out nashorn 15 and seems it is impossible to run without putting it on the module-path.
Given this code:
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 15+
//DEPS info.picocli:picocli:4.5.0
//DEPS org.openjdk.nashorn:nashorn-core:15.0
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.concurrent.Callable;
@Command(name = "js", mixinStandardHelpOptions = true, version = "js 0.1",
description = "js made with jbang")
class js implements Callable<Integer> {
@Parameters(index = "0", description = "The script to evaluate", defaultValue = "print('Hello, World!');")
private String script;
public static void main(String... args) {
int exitCode = new CommandLine(new js()).execute(args);
System.exit(exitCode);
}
@Override
public Integer call() throws Exception { // your business logic goes here...
// create a script engine manager
ScriptEngineManager factory = new ScriptEngineManager();
// create a Nashorn script engine
ScriptEngine engine = factory.getEngineByName("nashorn");
// evaluate JavaScript statement
try {
engine.eval(script);
} catch (final ScriptException se) { se.printStackTrace(); }
return CommandLine.ExitCode.OK;
}
}
jbang generates something like:
/Users/max/.jbang/cache/jdks/15/bin/java -classpath /Users/max/.jbang/cache/jars/js.java.a7d04aef6dd8094dd0e474c09e2e936e8506009e9bdceb96e238d1febc09be2e.jar --module-path /Users/max/.m2/repository/info/picocli/picocli/4.5.0/picocli-4.5.0.jar:/Users/max/.m2/repository/org/openjdk/nashorn/nashorn-core/15.0/nashorn-core-15.0.jar:/Users/max/.m2/repository/org/ow2/asm/asm/7.3.1/asm-7.3.1.jar:/Users/max/.m2/repository/org/ow2/asm/asm-commons/7.3.1/asm-commons-7.3.1.jar:/Users/max/.m2/repository/org/ow2/asm/asm-analysis/7.3.1/asm-analysis-7.3.1.jar:/Users/max/.m2/repository/org/ow2/asm/asm-tree/7.3.1/asm-tree-7.3.1.jar:/Users/max/.m2/repository/org/ow2/asm/asm-util/7.3.1/asm-util-7.3.1.jar js
with everything on classpath - this fails and nashorn is not available.
but if you change it to :
/Users/max/.jbang/cache/jdks/15/bin/java -classpath /Users/max/.jbang/cache/jars/js.java.a7d04aef6dd8094dd0e474c09e2e936e8506009e9bdceb96e238d1febc09be2e.jar:/Users/max/.m2/repository/info/picocli/picocli/4.5.0/picocli-4.5.0.jar --module-path /Users/max/.m2/repository/org/openjdk/nashorn/nashorn-core/15.0/nashorn-core-15.0.jar:/Users/max/.m2/repository/org/ow2/asm/asm/7.3.1/asm-7.3.1.jar:/Users/max/.m2/repository/org/ow2/asm/asm-commons/7.3.1/asm-commons-7.3.1.jar:/Users/max/.m2/repository/org/ow2/asm/asm-analysis/7.3.1/asm-analysis-7.3.1.jar:/Users/max/.m2/repository/org/ow2/asm/asm-tree/7.3.1/asm-tree-7.3.1.jar:/Users/max/.m2/repository/org/ow2/asm/asm-util/7.3.1/asm-util-7.3.1.jar js
the only change is inject of --module-path before the nashorn deps ...things work.
That makes me think that a simple improvement we could do is to do this:
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 15+
//DEPS info.picocli:picocli:4.5.0
//MDEPS org.openjdk.nashorn:nashorn-core:15.0
and let those deps found via MDEPS be fed into --module-path entry.
That would at least let things work for this case.
wanted to try out nashorn 15 and seems it is impossible to run without putting it on the module-path.
Given this code:
jbang generates something like:
with everything on classpath - this fails and nashorn is not available.
but if you change it to :
the only change is inject of
--module-pathbefore the nashorn deps ...things work.That makes me think that a simple improvement we could do is to do this:
and let those deps found via MDEPS be fed into
--module-pathentry.That would at least let things work for this case.