Java中的奇怪错误

时间:2012-07-11 09:18:05

标签: 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

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

1 个答案:

答案 0 :(得分:1)

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

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