Thanks Remi, although I don’t think that’s it.

To wit, if I write a minimal executable example:

---
import javax.script.*;

public class X {
    public static void main(String[] args) throws ScriptException {
        ScriptEngineManager factory = new ScriptEngineManager(); 
        ScriptEngine engine = factory.getEngineByName("nashorn"); 
        engine.eval("print('Hello, World!');");
    }
}
---

then run it with from my Nashorn project directory after it downloaded 
dependencies and built the JAR (so they’re in the directories named on the 
command line):

$ java --module-path build/nashorn/dependencies:build/nashorn/dist X.java

it works, so seemingly service discovery is just fine with only the declaration 
in module-info.java.

 
Further, in my test app on GitHub I even switched to using 
NashornScriptEngineFactory directly, so that it doesn’t rely on the service 
discovery mechanism, and then it fails with:

java.lang.IllegalArgumentException: Null module name
        at 
java.base/jdk.internal.module.Checks.requireModuleName(Checks.java:46) ~[na:na]
        at 
java.base/java.lang.module.ModuleDescriptor$Builder.requires(ModuleDescriptor.java:1646)
 ~[na:na]
        at 
java.base/java.lang.module.ModuleDescriptor$Builder.requires(ModuleDescriptor.java:1667)
 ~[na:na]
        at 
org.openjdk.nashorn.internal.runtime.StructureLoader.createModule(StructureLoader.java:68)
 ~[nashorn-core-15.0.jar:na]
        ...

which is further evidence that Spring Boot is not loading Nashorn as a JPMS 
module.

Attila.


> On 2020. Dec 13., at 18:07, Remi Forax <fo...@univ-mlv.fr> wrote:
> 
> Hi Attila,
> for compatibility, you have to both use the new module-info descriptor and 
> the old META-INFO/services when you declare a service.
> 
> It's a shame that jar doesn't do that by itself, it was something we 
> (module/jigsaw EG) discussed but it was never implemented.
> 
> regards,
> Rémi
> 
> ----- Mail original -----
>> De: "Attila Szegedi" <szege...@gmail.com>
>> À: "nashorn-dev" <nashorn-dev@openjdk.java.net>
>> Envoyé: Dimanche 13 Décembre 2020 17:54:06
>> Objet: Nashorn + Spring Boot; help appreciated
> 
>> Hey folks,
>> 
>> seems like folks are trying to use standalone Nashorn with Spring Boot, and 
>> are
>> running into an issue where Boot doesn’t load Nashorn as a JPMS module. If
>> anyone has expertise with this (Spring Boot loading app dependencies as JPMS
>> modules) and can help it’d be most appreciated.
>> 
>> I outlined the problem (and I even have a very small reproducer Boot app) in 
>> a
>> comment on Stack Overflow[0], if you want to help, you’ll find the details
>> there.
>> 
>> Thank you,
>> Attila.
>> 
>> [0]
>> https://stackoverflow.com/questions/65265629/how-to-use-nashorn-in-java-15-or-later/65278158#65278158

Reply via email to