使用'extends'编译.java的Java失败

时间:2016-08-01 23:12:40

标签: java

我正在尝试从here编译OSX上的pentaho样本。

Sample1.java扩展了AbstractReportGenerator.java。

我已在控制台中导出CLASSPATH以包含pwd:

export CLASSPATH=/Users/xxx/java-dev/pentaho/:/Users/xxx/java-dev/pentaho/lib/

我已使用AbstractReportGenerator.javajavac成功编译到与Sample1.java文件相同的文件夹中,但是当我尝试编译Sample1.java时,它总是失败并且有3个错误相关到AbstractReportGenerator

有关原因和解决方案的任何建议吗?

文件夹结构:

Working Folder >
 - Sample1.java
 - AbstractReportGenerator.java
 - AbstractReportGenerator.class
 - AbstractReportGenerator$1.class
 - AbstractReportGenerator$OutputType.class
 - lib
   - pentaho .jar files

命令:

javac -cp "lib/*" Sample1.java
Sample1.java:41: error: cannot find symbol
public class Sample1 extends AbstractReportGenerator
                             ^
  symbol: class AbstractReportGenerator
Sample1.java:61: error: cannot find symbol
      final ClassLoader classloader = this.getClass().getClassLoader();
                                          ^
  symbol: method getClass()
Sample1.java:132: error: package AbstractReportGenerator does not exist
    new Sample1().generateReport(AbstractReportGenerator.OutputType.PDF, outputFilename);
                                                        ^
Note: Sample1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors

2 个答案:

答案 0 :(得分:0)

尝试使用:

javac -cp lib/*:. Sample1.java

答案 1 :(得分:0)

非常感谢所有建议,在添加目标文件夹之后,@ Roman Vottner的这个建议终于奏效了:

javac -cp ./lib/*:./target -d ./target AbstractReportGenerator.java Sample1.java