java.lang.noclassdeffounderror:jdk/nashorn/api/scripting/nashornscriptenginefactory

c6ubokkw  于 2021-07-06  发布在  Java
关注(0)|答案(2)|浏览(812)

我想在1.16.3中编写一个minecraft mod。我已经在1.12.2中做了一个mod,但是我没有这个问题。我只是下载了1.16.3 forge mdk并为eclipse构建了它(cmd中带有“gradlew eclipse”),但是当我尝试运行mod时(带有“runclient.launch”)。它给出了一个错误:
noclassdeffounderror:jdk/nashorn/api/scripting/nashornscriptenginefactory。
我试图修改主文件和包,以支持不需要的代码,但当我开始。它给了我同样的错误。
我的主文件:

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");
//        }
//    }
}

以及堆栈跟踪:

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
1u4esq0p

1u4esq0p1#

看起来你使用的minecraft代码依赖于nashorn脚本引擎。nashorn从java15中的jdk中删除了,您似乎正在运行它。
降级到JDK14或更早的版本。

erhoui1w

erhoui1w2#

解决方案

nashorn在java15中从jdk中删除(https://openjdk.java.net/jeps/372)
您需要使用Java1.8启动(以避免不支持ClassVersionError)
所以你必须:
Project Properties >> Java compiler >> Compiler >> compilance level 并修改为JavaSE-1.8
修改路径(放入jdk1.8)
如果这不起作用,去 Preferences >> Java >> Installed JREs 以及 Preferences >> Java >> Installed JREs >> Execution Environments 感谢@lukewoodward!!

相关问题