我使用JavaPoet生成一些类。全对了!但我需要将该代码生成到src文件夹中,而不是生成目标,也不生成bin或类文件夹
现在,我使用以下代码编写类:
URL[] urls = ((URLClassLoader) Thread.currentThread().getContextClassLoader()).getURLs();
File root = new File(urls[0].toURI()); // this is 'target' folder
File source = new File(root, packageName.replace(".", "/").concat("/").concat(className).concat(".java"));
FileWriter writer = new FileWriter(source);
JavaFile.builder(packageName, spec).build().writeTo(writer);