Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法让Janino编译器编译与jar位于同一目录中的文件_Java_Compiler Construction_Janino - Fatal编程技术网

Java 无法让Janino编译器编译与jar位于同一目录中的文件

Java 无法让Janino编译器编译与jar位于同一目录中的文件,java,compiler-construction,janino,Java,Compiler Construction,Janino,我正在使用Janino在运行时编译java文件,以便在程序中使用。我使用的是netbeans,只有当我将目录放入src文件夹时,我才能在运行时编译它。如果我尝试使用相对路径编译它,它将不起作用 我在下面的例子 当我将要在运行时编译的文件放在src目录中名为scripts的文件夹中时,以下是有效的方法: String engineClass = "DefaultEngine"; //name of engine class String guiClass = "De

我正在使用Janino在运行时编译java文件,以便在程序中使用。我使用的是netbeans,只有当我将目录放入src文件夹时,我才能在运行时编译它。如果我尝试使用相对路径编译它,它将不起作用

我在下面的例子

当我将要在运行时编译的文件放在src目录中名为scripts的文件夹中时,以下是有效的方法:

        String engineClass = "DefaultEngine"; //name of engine class
        String guiClass = "DefaultGUI"; // name of gui class
        ClassLoader cl = new JavaSourceClassLoader(
                this.getClass().getClassLoader(),
                new File[]{new File("scripts")},
                (String) null,
                DebuggingInformation.NONE);
        AbstractEngine engine = (AbstractEngine) cl.loadClass(engineClass).newInstance();
        AbstractGUI gui = (AbstractGUI) cl.loadClass(guiClass).newInstance();
如果我把scripts文件夹和jar放在同一个目录中,它就不起作用了。 只有在使用src目录中的scripts文件夹从IDE内部运行项目时,我才能让它工作

当我尝试使用与jar文件位于同一文件夹中的scripts文件夹运行项目时,它会在
AbstractEngine=AbstractEngine cl.loadClassengineClass.newInstance;行

我想出来了。我必须为路径添加新的FileSystem.getPropertyuser.dir+/scripts