I am trying to dynamically compile java classes in runtime. The java files gets generated in System.getProperty("java.io.tmpdir")
folder. When it is done generated the java files get compiled being used it gets deleted. My method of dynamically compilation is grabbed from this question
How do you dynamically compile and load external java classes?
Now in my test classes they successfully get generated, compiled and loaded but when I do a mvn:clean install and maven runs through the tests then suddenly the packages used in the generated classes can not be found. One of the tests I wrote, calls the method and then generates these classes, it is kind of lazy loading where only when the generated classes is needed by other code it gets generated.
/tmp/java/CH3.java:3: error:
package foo.bar does not exist
import foo.bar.Generated;
/tmp/java/CH3.java:17: error:
cannot find symbol
Generated generated
^
I assume it has something to do with the ClassLoader or JavaFileManager not containing the packages it needs for the java file to get compiled.
Also this error occurs the moment the compiler tries to compile the java file.
Do you have any idea how to fix this problem ?