How to get list of class files generated by JavaCompiler compilationTask?

后端 未结 2 759
渐次进展
渐次进展 2021-01-15 17:30

I am trying to compile java code dynamically using javaCompiler. Code works gr8 however I need to get the list of class files created by CompilationTask. Here is source code

2条回答
  •  梦毁少年i
    2021-01-15 18:05

    The javax.tools.JavaCompiler#getTask() method takes an options parameter that allows to set compiler options. Set the destination directory for class files using -d option

    List options = new ArrayList();
    // Sets the destination directory for class files
    options.addAll(Arrays.asList("-d","/home/myclasses"));
    
    CompilationTask task = compiler.getTask (null,fileManager, diagnostics, options, null, compilationUnits);
    

    Now get all the files with .class extentions

提交回复
热议问题