Giter Club home page Giter Club logo

Comments (11)

Losin6450 avatar Losin6450 commented on August 25, 2024

its specifically the File.exists() method that doesn't work

from javet.

caoccao avatar caoccao commented on August 25, 2024

Please leave more info for the troubleshooting. OS, CPU arch, source code, etc.

from javet.

Losin6450 avatar Losin6450 commented on August 25, 2024

its for a Minecraft plugin

public class Grakkit extends JavaPlugin implements CommandExecutor {

    V8Runtime runtime;
    JavetJVMInterceptor interceptor;
    @Override
    public void onEnable() {
        try {
            saveDefaultConfig();
            reloadConfig();
            String main = getConfig().getString("main", "index.js");
            String mode = getConfig().getString("mode", "js");
            if (mode.equalsIgnoreCase("node")){
                runtime = V8Host.getNodeInstance().createV8Runtime();
            } else {
                runtime = V8Host.getV8Instance().createV8Runtime();
            }
            runtime.setConverter(new JavetProxyConverter());
            interceptor = new JavetJVMInterceptor(runtime);
            interceptor.register(runtime.getGlobalObject());
            runtime.setV8ModuleResolver(new IV8ModuleResolver() {

                private Path DEFAULT = getDataFolder().toPath();
                private Path LAST = getDataFolder().toPath();

                @Override
                public IV8Module resolve(V8Runtime v8Runtime, String file, IV8Module iv8Module) throws JavetException {
                    try {
                        String filename = file.endsWith(".js") ? file : file + ".js";
                        Path f = LAST.resolve(filename);
                        if (Files.exists(f)) {
                            LAST = f.getParent();
                            V8Module module = v8Runtime.getExecutor(Files.lines(f).collect(Collectors.joining("\n"))).setResourceName(f.toFile().getAbsolutePath()).compileV8Module();
                            return module;
                        } else {
                            LAST = DEFAULT;

                            f = LAST.resolve(filename);
                            if (Files.exists(f)) {
                                LAST = f.getParent();
                                V8Module module = v8Runtime.getExecutor(Files.lines(f).collect(Collectors.joining("\n"))).setResourceName(f.toFile().getAbsolutePath()).compileV8Module();
                                return module;
                            }
                            return null;
                        }
                    } catch (Exception e){
                        e.printStackTrace();
                    }
                    return null;
                }
            });
            runtime.allowEval(true);
            runtime.getGlobalObject().set("Class", Class.class);
            runtime.getGlobalObject().set("Logger", getLogger());
            File file = new File(getDataFolder(), main);
            if (!file.exists()){
                file.getParentFile().mkdirs();
                file.createNewFile();
            }
            V8StringExecutor stringExecutor = (V8StringExecutor) runtime.getExecutor(Files.lines(file.toPath()).collect(Collectors.joining("\n")));
            stringExecutor.setModule(true);
            stringExecutor.setResourceName(file.getAbsolutePath());
            stringExecutor.execute();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void onDisable() {
        if (runtime != null){
            try {
                runtime.await();
                interceptor.unregister(runtime.getGlobalObject());
                runtime.close();
                System.gc();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

}
``` when using normal v8 runtime there is no issues but when using node i get this error when trying to use java.io.File 

java.io.IOException: Den angivne sti blev ikke fundet
at java.io.WinNTFileSystem.createFileExclusively(Native Method) ~[?:1.8.0_412-412]
at java.io.File.createTempFile(File.java:2063) ~[?:1.8.0_412-412]
at net.minecraft.server.v1_16_R2.Convertable$ConversionSession.a(Convertable.java:303) ~[spigot.jar:git-Spigot-b5a13e6-0d8350a]
at net.minecraft.server.v1_16_R2.WorldServer.save(WorldServer.java:768) ~[spigot.jar:git-Spigot-b5a13e6-0d8350a]
at net.minecraft.server.v1_16_R2.MinecraftServer.saveChunks(MinecraftServer.java:674) ~[spigot.jar:git-Spigot-b5a13e6-0d8350a]
at net.minecraft.server.v1_16_R2.MinecraftServer.stop(MinecraftServer.java:741) ~[spigot.jar:git-Spigot-b5a13e6-0d8350a]
at net.minecraft.server.v1_16_R2.DedicatedServer.stop(DedicatedServer.java:647) ~[spigot.jar:git-Spigot-b5a13e6-0d8350a]
at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:887) ~[spigot.jar:git-Spigot-b5a13e6-0d8350a]
at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot.jar:git-Spigot-b5a13e6-0d8350a]

from javet.

caoccao avatar caoccao commented on August 25, 2024

It seems to be a permission issue?

from javet.

Losin6450 avatar Losin6450 commented on August 25, 2024

It only happens when using the node runtime, doesn't happen when using v8 runtime

from javet.

caoccao avatar caoccao commented on August 25, 2024

Well, I don't play Minecraft. Here are some ideas for your reference.

  • Create a regular Java app with the same code, deploy that app to the same env to see if things break.
  • Call File API in Java to see if it works.

from javet.

AsyncProxy avatar AsyncProxy commented on August 25, 2024

使用节点实例时,java.io.File 类不起作用

If you write Spigot/Fabric/Forge plugins or mods, you can embed the Rhino engine, otherwise the plugins will be very large, and my suggestion is to use them more widely for embedded apps.

from javet.

AsyncProxy avatar AsyncProxy commented on August 25, 2024

好吧,我不玩 Minecraft。以下是一些想法供您参考。

  • 使用相同的代码创建一个常规的 Java 应用程序,将该应用程序部署到同一个环境,看看是否有问题。
  • 在 Java 中调用 API 以查看它是否有效。File

Pls what happened to the problem that the engine of 3.1.2 does not work, I still can't run, no code has been changed, 3.1.1 is working normally.

from javet.

Losin6450 avatar Losin6450 commented on August 25, 2024

after alot of trial and error the issue seems to come from the setResourceName method on the executor

from javet.

caoccao avatar caoccao commented on August 25, 2024

You may workaround it if it causes issues at your end. Please refer to this commit for detail.

from javet.

caoccao avatar caoccao commented on August 25, 2024

It's now surrounded by a try-catch clause so that that error can be omitted and logged.

from javet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.