Java - 从命令行编译 - 外部jar

时间:2013-03-19 15:52:46

标签: java

我正在使用这个库来编译java程序。我正在使用eclipse,但我也想尝试从命令行编译它(它将通过命令行执行)。它似乎正在研究Eclipse。

我在命令行中尝试了这个,它似乎正在运行:

javac -cp ../lib/jxl.jar Main.java

但它给了我这个:

Main.java:5: cannot find symbol
symbol  : class Reader
location: class Main
    Reader excel_reader = new Reader();
    ^
Main.java:5: cannot find symbol
symbol  : class Reader
location: class Main
    Reader excel_reader = new Reader();

我只有2个类,Main(只有main方法)和Reader。这两个文件都在eclipse工作区的src /文件夹下。

读者课程:

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class Reader {
  private String inputFile;

  public void setInputFile(String inputFile) {
    this.inputFile = inputFile;
  }

  public void read() throws IOException  {
    File inputWorkbook = new File(inputFile);
    Workbook w;
    try {
      w = Workbook.getWorkbook(inputWorkbook);
      // Get the first sheet
      Sheet sheet = w.getSheet(0);
      // Loop over first 10 column and lines

      for (int j = 0; j < sheet.getColumns(); j++) {
        for (int i = 0; i < sheet.getRows(); i++) {
          Cell cell = sheet.getCell(j, i);
          CellType type = cell.getType();
          if (type == CellType.LABEL) {
            System.out.println("I got a label "
                + cell.getContents());
          }

          if (type == CellType.NUMBER) {
            System.out.println("I got a number "
                + cell.getContents());
          }

        }
      }
    } catch (BiffException e) {
      e.printStackTrace();
    }
  }

}

主类

import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    Reader excel_reader = new Reader();
    excel_reader.setInputFile("Excel_Spreadsheets/Dictionary_Part2.xls");
    excel_reader.read();
  }
}

0 个答案:

没有答案