문제

I'm trying to compile many files using the Compiler API.

Say I have a directory structure

.../program
   +/org
    +/foo
    |+ Main.java
    +/bar
     + Tools.java

Is there any way to discover all the Java files and make it compiler everything without resorting to recursing into all the directories and finding all the *.java files?

EDIT: What I'm trying to do is compile all the classes that I get in some directory tree. These classes are independent of each other. Then I load the classes and instantiate some objects of these classes and call methods. None of the classes need to have main.

도움이 되었습니까?

해결책

The javax.tools.JavaFileManager class has a list() method that should do the trick:

Iterable<JavaFileObject> list(JavaFileManager.Location location,
                              String packageName,
                              Set<JavaFileObject.Kind> kinds,
                              boolean recurse)
                              throws IOException

Use the recurse parameter to include "subpackages" and then just iterate over the returned JavaFileObject.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top