如何生成java代码到src文件夹不是bin也不是target?

时间:2017-12-29 17:11:29

标签: java javapoet

我使用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);

0 个答案:

没有答案