java - Java中的奇怪错误

标签 java jar compilation classpath javac

<分区>

谁能说出为什么会出现此错误,因为如果您将工作放在终端中?这是代码。

我使用这段代码来编译一个文件夹中的所有文件。

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Compiles {
    public static void main(String[] args) {
            List<String> compileFileCommand = new ArrayList<String>();
            List<String> files = new FileList().getListFile();
            List<String> libs = new ListLib().getListFile();
            compileFileCommand.add("/opt/java/bin/javac");

            for(int i = 0; i < files.size(); i++)
            {

                if(files.get(i).equals("Compiles.java"))
                    continue;

                if(files.get(i).equals("Compile.java"))
                    continue;

                String fileJar = new CreateFolder().currentData() + "/" + files.get(i) + " -cp lib/";

   //                       for (int y = 0; y < libs.size(); y++)
   //                       {
  //                            fileJar += libs.get(y) + ":";
  //                            if(libs.size() -1 == y)
  //                                fileJar += libs.get(y);  
  //                        }

                    fileJar += libs.get(0);



                    compileFileCommand.add(fileJar);

                    Process compile_process;
                    try {
                            compile_process = new ProcessBuilder(compileFileCommand)
                                            .redirectErrorStream(true).start();
                    } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            return;
                    }
                    try {
                            compile_process.waitFor();
                    } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    }

                    BufferedReader reader = new BufferedReader(new InputStreamReader(
                                    compile_process.getInputStream()));
                    String line = null;
                    try {
                            line = reader.readLine();
                    } catch (IOException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                    }
                    while (line != null) {
                            System.out.println(line);
                            try {
                                    line = reader.readLine();
                            } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                            }
                    }
            }
    }
}

错误如下

javac: invalid flag: temp_11.07.2012/CreateFolder.java -cp lib/gdata-media-1.0.jar
Usage: javac <options> <source files>
use -help for a list of possible options

这些是数据的例子,这就是给出的

最佳答案

您是否尝试将“-cp”选项放在要编译的文件名之前?

如果不是那样,请给我们完整的命令行。

关于java - Java中的奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11429392/

相关文章:

java - XML解析: counting the number of sub elements

java - 在 Android 中使用 MySql 项目将 JSON 转换为字符串

java - 在类路径中包含太多 jar 文件的影响

java - 从另一个 jar 运行一个 jar

ios - 为什么 XCode 4.2 中的 three20 依赖项不再需要 -force_load?

c++ - Code::Blocks "compile switches"在哪里?

java - 用于车牌的 Opencv 图像分割

java - 遍历一棵树,但访问的每个节点都应该访问下面的每个节点

java - Jar 不可见,但 javaw.exe 正在运行

compiler-errors - 为什么 HDF5 在这里给出 "too few arguments"错误?