I writed a code that generates two class which I write them to buffer and compile them with JavaCompiler. My classes are like this in .java files;
public class A{
public A() { }
public String toString(){ return "A";}
}
and
public class B extends ArrayList<A> {
public B() {
super();
}
public void addItem(A a)
{
this.add(a);
}
public void print() {
this.print();
}
}
something like this.
However, the name of the classes are randomly generated and when I create the file it gives an error like this;
symbol: class A
location: class B
./src/A.java:4: error: cannot find symbol
(4th line is the "...extends ArrayList..." and there is a ^ symbol under A)
My code generator compiles like this;
First I fill the buffer with my template for A type classes then compile like this:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
compiler.run(null, null, null, f.getPath());
after that I create another buffer and fill it with my template for B type classes then compile like this;
System.out.println(f.getParentFile().getPath());
compiler.run(null, null, null, f.getPath());
f is;
f = new File(("./src/" + name + ".java"));
How can I solve this problem?