Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.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.nio.file.InvalidPathException:非法字符<;:&燃气轮机;使用闭包编译器格式化javascript文件时,在索引7处_Java_Processbuilder_Google Closure Compiler - Fatal编程技术网

获取java.nio.file.InvalidPathException:非法字符<;:&燃气轮机;使用闭包编译器格式化javascript文件时,在索引7处

获取java.nio.file.InvalidPathException:非法字符<;:&燃气轮机;使用闭包编译器格式化javascript文件时,在索引7处,java,processbuilder,google-closure-compiler,Java,Processbuilder,Google Closure Compiler,我正在使用googleclosurecompiler格式化我的web项目中的许多javascript文件。因此,我正在编写一个Java应用程序来遍历根目录下的所有js文件。出于测试目的,我只对单个javascript文件进行了一次尝试,如下所示: public static void main(String[] args){ JSBeautifier js = new JSBeautifier(); js.beautify("'C:/CodeScanner/src

我正在使用googleclosurecompiler格式化我的web项目中的许多javascript文件。因此,我正在编写一个Java应用程序来遍历根目录下的所有js文件。出于测试目的,我只对单个javascript文件进行了一次尝试,如下所示:

public static void main(String[] args){
        JSBeautifier js = new JSBeautifier();
        js.beautify("'C:/CodeScanner/src/test/resources/testJS.js'");
    }

    public void beautify(String filePath) {
        String srcFileArg = "--js " + filePath;

        ProcessBuilder pb = new ProcessBuilder("java", "-jar" , "compiler.jar", srcFileArg).inheritIO();

        try {
            Process p  = pb.start();
            p.waitFor();
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            while(br.readLine() != null){
                System.out.println(br.readLine());
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
但是,当执行时,会出现异常:

Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 7: --js 'C:/CodeScanner/src/test/resources/testJS.js'
    at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
    at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
    at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
    at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
    at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
    at java.nio.file.Paths.get(Paths.java:84)
    at com.google.javascript.jscomp.CommandLineRunner.findJsFiles(CommandLineRunner.java:1753)
    at com.google.javascript.jscomp.CommandLineRunner.findJsFiles(CommandLineRunner.java:1730)
    at com.google.javascript.jscomp.CommandLineRunner$Flags.getJsFiles(CommandLineRunner.java:928)
    at com.google.javascript.jscomp.CommandLineRunner.initConfigFromFlags(CommandLineRunner.java:1325)
    at com.google.javascript.jscomp.CommandLineRunner.<init>(CommandLineRunner.java:1176)
    at com.google.javascript.jscomp.CommandLineRunner.main(CommandLineRunner.java:1834)
线程“main”java.nio.file.InvalidPathException中的异常:索引7处的非法字符:--js'C:/CodeScanner/src/test/resources/testJS.js' 位于sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) 位于sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153) 位于sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) 位于sun.nio.fs.WindowsPath.parse(WindowsPath.java:94) 位于sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255) 位于java.nio.file.Paths.get(path.java:84) 位于com.google.javascript.jscomp.CommandLineRunner.findJsFiles(CommandLineRunner.java:1753) 位于com.google.javascript.jscomp.CommandLineRunner.findJsFiles(CommandLineRunner.java:1730) 位于com.google.javascript.jscomp.CommandLineRunner$Flags.getJsFiles(CommandLineRunner.java:928) 位于com.google.javascript.jscomp.CommandLineRunner.initConfigFromFlags(CommandLineRunner.java:1325) 位于com.google.javascript.jscomp.CommandLineRunner.(CommandLineRunner.java:1176) 位于com.google.javascript.jscomp.CommandLineRunner.main(CommandLineRunner.java:1834) 在命令行中,可以成功执行此操作(java-jar compiler.jar--js'C:/CodeScanner/src/test/resources/testJS.js)


谁能帮忙吗

看起来ProcessBuilder正在尝试执行:

java "-jar" "compiler.jar" "--js 'C:/CodeScanner/src/test/resources/testJS.js'"
这导致js编译器看到:

argv[0] = "--js 'C:/CodeScanner/src/test/resources/testJS.js'"
而不是:

argv[0] = "--js"
argv[1] = "'C:/CodeScanner/src/test/resources/testJS.js'"
要更正此问题,我将尝试更改:

String srcFileArg = "--js " + filePath;
ProcessBuilder pb = new ProcessBuilder("java", "-jar" , "compiler.jar", srcFileArg).inheritIO();
进入


看起来ProcessBuilder正在尝试执行:

java "-jar" "compiler.jar" "--js 'C:/CodeScanner/src/test/resources/testJS.js'"
这导致js编译器看到:

argv[0] = "--js 'C:/CodeScanner/src/test/resources/testJS.js'"
而不是:

argv[0] = "--js"
argv[1] = "'C:/CodeScanner/src/test/resources/testJS.js'"
要更正此问题,我将尝试更改:

String srcFileArg = "--js " + filePath;
ProcessBuilder pb = new ProcessBuilder("java", "-jar" , "compiler.jar", srcFileArg).inheritIO();
进入


谢谢。解释很清楚,您知道“-formatting”是否不适用于上述方法吗?我尝试添加--格式化漂亮的打印,但没有任何效果。这样做的目的是我只想从我的js文件中删除空行和注释,但保留换行符。应该这样做。尝试将
--formatting=“PRETTY_PRINT”
作为单个参数。Thx。解释很清楚,您知道“-formatting”是否不适用于上述方法吗?我尝试添加--格式化漂亮的打印,但没有任何效果。这样做的目的是我只想从我的js文件中删除空行和注释,但保留换行符。应该这样做。尝试将
--formatting=“PRETTY\u PRINT”
作为单个参数。