3

I want to code a Minecraft mod in 1.16.3. I have already make a mod in 1.12.2 but I didn't have this problem. I just download the 1.16.3 forge Mdk and build it for eclipse (with 'gradlew eclipse' in cmd) but when I try to run the mod (with 'runClient.launch'). It gives an error:

java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/NashornScriptEngineFactory.

I tried to modify the main file and packages to support the not necessary code but when I start. It gives me the same error.

My main file:

package fr.luzog78.newmod;

import net.minecraft.block.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod("newmod")
public class NewMod {
    private static final Logger LOGGER = LogManager.getLogger();

    public NewMod() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event) {
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
    }

//    @SubscribeEvent
//    public void onServerStarting(FMLServerStartingEvent event) {
//        // do something when the server starts
//        LOGGER.info("HELLO from server starting");
//    }
//
//    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
//    // Event bus for receiving Registry Events)
//    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
//    public static class RegistryEvents {
//        @SubscribeEvent
//        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
//            // register a new block here
//            LOGGER.info("HELLO from Register Block");
//        }
//    }
}

And the stack trace:

Exception in thread "main" [13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]: java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/NashornScriptEngineFactory
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at net.minecraftforge.coremod.CoreModEngine.loadCoreMod(CoreModEngine.java:48)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at net.minecraftforge.coremod.CoreModProvider.addCoreMod(CoreModProvider.java:12)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:274)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at net.minecraftforge.fml.loading.LoadingModList.addCoreMods(LoadingModList.java:85)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer.discoverMods(ModDiscoverer.java:129)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at net.minecraftforge.fml.loading.FMLLoader.beginModScan(FMLLoader.java:213)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at net.minecraftforge.fml.loading.FMLServiceProvider.runScan(FMLServiceProvider.java:107)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at cpw.mods.modlauncher.TransformationServiceDecorator.runScan(TransformationServiceDecorator.java:114)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at cpw.mods.modlauncher.TransformationServicesHandler.lambda$runScanningTransformationServices$8(TransformationServicesHandler.java:115)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1766)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at cpw.mods.modlauncher.TransformationServicesHandler.runScanningTransformationServices(TransformationServicesHandler.java:116)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:63)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at cpw.mods.modlauncher.Launcher.run(Launcher.java:76)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1048]:   at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1057]: Caused by: java.lang.ClassNotFoundException: jdk.nashorn.api.scripting.NashornScriptEngineFactory
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1057]:   at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1057]:   at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1057]:   at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
[13:16:47] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1057]:   ... 33 more
Dharman
  • 30,962
  • 25
  • 85
  • 135
Luzog78
  • 53
  • 1
  • 1
  • 5
  • the main issue is that the class `jdk/nashorn/api/scripting/NashornScriptEngineFactory` can't be found by the compiler. When compiling your code (with javac or some build managent tool like ant?) you need to make sure that that class is located inside your classpath (configureable with -cp) – schetefan24 Nov 14 '20 at 13:21
  • Which Java version are you using ? – Joby Wilson Mathews Nov 14 '20 at 13:37
  • @schetefan24 , Sorry but idk how do that ... x) srry – Luzog78 Nov 14 '20 at 15:24
  • @JobyWilsonMathews ```java version "15.0.1" 2020-10-20 Java(TM) SE Runtime Environment (build 15.0.1+9-18) Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)``` But I have already test With java 8 – Luzog78 Nov 14 '20 at 15:26

2 Answers2

6

It seems the Minecraft code you are using depends on the Nashorn scripting engine. Nashorn was removed from the JDK in Java 15, which it seems you are running.

Downgrade to JDK 14 or an earlier version.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
  • OOOOhhhh thank youuu verry much !! That works !! Thanks I was sure I had already done it but.. no xD Thanks !!! – Luzog78 Nov 14 '20 at 15:38
  • But now i have "java.lang.UnsupportedClassVersionError" x) – Luzog78 Nov 14 '20 at 15:40
  • No its good... i had forgotten modify the path but that works only in jdk1.8 – Luzog78 Nov 14 '20 at 15:46
  • Why was it removed? I already can see how this question and answer will receive thousands of views in the next few years... – Akito Jan 27 '21 at 21:10
  • @Akito: does the link above not explain it? – Luke Woodward Jan 27 '21 at 21:11
  • @LukeWoodward It's a good enough explanation for many use-cases perhaps, but, in my opinion, not for Java. 1. Java is extremely popular and has tons of projects that need to be maintained. 2. This is not some minor change, else I wouldn't have found this page. 3. Whoever deals with this huge bloat called "Java" probably does not care if such a module is included or not. Java is pretty much pure bloat, so you might as well keep support for such modules. – Akito Jan 27 '21 at 21:15
2

Solution


  • Nashorn was removed from the JDK in Java 15 (https://openjdk.java.net/jeps/372)
  • You need to launch with Java 1.8 (to avoid UnsupportedClassVersionError)
  • So you have to :
    1. Go to Project Properties >> Java compiler >> Compiler >> compilance level and modify to Java SE - 1.8
    2. Modify your path (put jdk1.8)
    3. And if that not works, go to Preferences >> Java >> Installed JREs and Preferences >> Java >> Installed JREs >> Execution Environments

Thanks to @LukeWoodward !!

Luzog78
  • 53
  • 1
  • 1
  • 5