开发者

Compiling a set of Java files inside a directory tree with the JSR 199 Compiler API

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 with开发者_如何学Goout 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜