只编译源代码树与蚂蚁的一部分 [英] compiling only part of the source tree with ant

查看:214
本文介绍了只编译源代码树与蚂蚁的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有我的消息来源在我的src /树(也可能在我的测试/树)。说我想只编译那棵树的部分的。为什么我会想这样做,有各种原因。只是作为一个例子,我可能希望创建尽可能小的罐子(不包括某些类),或者我可能想以最快的编译时间,什么我编译。我绝对要编译所有的依赖关系,尽管!

Say I have my sources in my src/ tree (and possibly in my test/ tree). Say I would like to compile only part of that tree. The reasons why I might want to do that are various. Just as an example, I might want to create the smallest possible jar (without including certain classes), or I might want the fastest compile time for what I am compiling. I absolutely want to compile all the dependencies, though!

此能够容易地从所述命令行与实现的:

This can be easily achieved from the command line with:

javac -d build/ -cp whatever -sourcepath src src/path/to/MyClass.java

现在,你怎么能做到这一点与蚂蚁? javac的蚂蚁任务编译一切

Now, how can you do that with ant? The javac ant task compiles everything:

源和目标目录
  将扫描递归的Java
  源文件进行编译。

The source and destination directory will be recursively scanned for Java source files to compile.

一个可以使用不包括包括参数,但他们为此问题。事实上,似乎一个人必须明确设置所有的包括(不是自动的依赖查找),和更坏excludes优先于包括

One can use the excludes and includes parameters, but they are problematic for this purpose. In fact, it seems that one has to explicitly setup all the includes (not automatic dependency lookup), and even worst that excludes has priority on includes:

当两者纳入和排除是
  使用时,只有文件/目录
  的比赛至少有一个包括
  图案和不匹配的任何的的
  排除模式被使用。

When both inclusion and exclusion are used, only files/directories that match at least one of the include patterns and don't match any of the exclude patterns are used.

因此​​,你不能使用

<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath"
            excludes="**/*.java" includes="src/path/to/MyClass.java" />  

由于它不会编译任何东西: - (

Because it will not compile anything :-(

有没有实现这个简单的命令行的javac 与蚂蚁的方法吗?

Is there any way of achieving that simple command line javac with ant?

编辑:谢谢您的回答,塞迪,我接受它,因为它在我在这个问题想的方式工作。但我有一对夫妇的意见(太长,不能在你的答案的注释字段):

EDITED: Thank you for your answer, Sadie, I'm accepting it, because it does work in the way I was wondering in this question. But I have a couple of comments (too long to be in the comment field of your answer):

1)我看过的文件(见上面的链接),但目前还不清楚认为,只要包括你实际上也排除一切

1) I did read the documentation (see links above), but it's unclear that with just includes you are actually also excluding everything else

2)当你刚包括蚂蚁日志类似

2) When you just includes ant logs something like

[javac] Compiling 1 source file to /my/path/to/build

即使依赖使它编译(多)不止一个源文件。

even if the dependencies make it compiling (much) more than just one source file.

推荐答案

为什么要排除以及包括?如果您至少有一个包括,那么文件只如果他们明确地纳入编制。所以这应该工作:

Why are you excluding as well as including? If you have at least one include, then files are only compiled if they're explicitly included. So this should work:

<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath"
        includes="src/path/to/MyClass.java" />

或者更灵活:

<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath">
    <include name="src/path/to/MyClass.java"/>
    <include name="src/path/to/AnotherClass.java"/>
</javac>

要只包括在一个罐子里的某些包或类,使用文件集属性

To include only certain packages or classes in a jar, use a fileset attribute

<jar jarfile="${outlib}/something.jar">
    <fileset dir="${build.dir}">
        <include name='src/path/to/classes' />
    </fileset>
</jar>

同样,你可以使用多个包含了单独的包结合起来。实验包括和阅读文档并你一定能找到你需要的答案。

Again, you can use multiple includes to combine separate packages. Experiment with includes and read the documentation and you're sure to find the answer you need.

这篇关于只编译源代码树与蚂蚁的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆