crankshaft crankshaft - 2 months ago 15
Java Question

Java compiling .java with 'extends' fails

I am trying to compile the pentaho samples on OSX from here.

Sample1.java extends AbstractReportGenerator.java.

I have exported the CLASSPATH in the console to include the pwd:

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


I have compiled
AbstractReportGenerator.java
successfully using
javac
, into the same folder as the
Sample1.java
file, however when I try and compile
Sample1.java
it always fails with 3 errors related to
AbstractReportGenerator
.

Any suggestion on the cause and solution ?

Folder structure:

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


Command:

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

Answer

Thanks so much for all the suggestions, after adding a target folder, this suggestion from @Roman Vottner finally worked:

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