Eclipse、ant 和自定义任务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/429907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse, ant and custom tasks
提问by Bill K
Sorry, I'm not terribly experienced with Ant.
抱歉,我对 Ant 的经验不是很丰富。
I like the eclipse "Export ant buildfile" function, but I need to insert a few custom tasks (Copying files, calculating checksums that are used at runtime, etc).
我喜欢 Eclipse 的“Export ant buildfile”功能,但我需要插入一些自定义任务(复制文件、计算在运行时使用的校验和等)。
How do I integrate custom ant tasks with the antfile that Eclipse exports? Also, once I've done so, will the internal build (Run...) pick it up or will I always have to use the external ant file to build from now on?
如何将自定义 ant 任务与 Eclipse 导出的 antfile 集成?另外,一旦我这样做了,内部构建(运行...)会选择它还是从现在开始我总是必须使用外部 ant 文件来构建?
Oh, and I don't want to edit the build.xml that is exported from Eclipse, because I'd like to be able to regenerate it later.
哦,我不想编辑从 Eclipse 导出的 build.xml,因为我希望以后能够重新生成它。
Edit/Update:
编辑/更新:
It took me a while to figure out what was going on--so I thought I'd put some notes here to clarify.
我花了一段时间才弄清楚发生了什么——所以我想我会在这里放一些笔记来澄清。
When you create a new ant file in your directory and put <?eclipse.ant.import ?>
on the first line of your custom ant script (I called mine test.xml), next time you export the buildfile from Eclipse into that directory, it'll see that tag and add <import file="test.xml"/>
当您在目录中创建一个新的 ant 文件并将其放在<?eclipse.ant.import ?>
自定义 ant 脚本的第一行(我称为我的 test.xml)时,下次您将构建文件从 Eclipse 导出到该目录时,它会看到该标记并添加<import file="test.xml"/>
With that Import, the targets in your "Custom" file (test.xml) become valid targets in your exported build.xml (or whatever name you chose when you exported it).
通过该导入,“自定义”文件 (test.xml) 中的目标将成为导出的 build.xml(或导出时选择的任何名称)中的有效目标。
After this, anytime you select "build.xml" in Eclipse, the targets pane will also include targets from "test.xml"
在此之后,无论何时您在 Eclipse 中选择“build.xml”,目标窗格也将包含来自“test.xml”的目标
Also, after that, you can go into your project properties/Builders and add a new builder of type "Ant Build", then select targets to use for building, clean, etc.
此外,之后,您可以进入项目属性/构建器并添加一个“Ant Build”类型的新构建器,然后选择用于构建、清理等的目标。
采纳答案by JesperE
The ant export filter will include any xml file in the same directory which has the special
ant 导出过滤器将在同一目录中包含任何具有特殊属性的 xml 文件
<?eclipse.ant.import?>
element as its first child.
元素作为它的第一个子元素。
Example:
例子:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse.ant.import?>
<project name="project" default="default" basedir=".">
...
</project>
Eclipse will now include the following line in build.xml
:
Eclipse 现在将包含以下行build.xml
:
<import file="custom_build.xml"/>
回答by Peter Hilton
If you write your own Ant script, you can write your own targets that use the Ant taskto delegate to the generated build.xml.
如果您编写自己的 Ant 脚本,则可以编写自己的目标,这些目标使用Ant 任务委派给生成的build.xml。
Also, you can configure a project's 'builders' (project properties ? Builders) to run any something different when you build the project, manually or automatically.
此外,您可以配置项目的“构建器”(项目属性?构建器)以在构建项目时手动或自动运行任何不同的东西。
回答by Andrew Niefer
PDE has support for custom callbacks from the generated build.xml into your own custom ant script.
PDE 支持从生成的 build.xml 到您自己的自定义 ant 脚本的自定义回调。
Copy the file "templates/plugins/customBuildCallbacks.xml" from the org.eclipse.pde.build in your eclipse install, and set "customBuildCallbacks=true" in your build.properties file.
从您的 eclipse 安装中的 org.eclipse.pde.build 复制文件“templates/plugins/customBuildCallbacks.xml”,并在您的 build.properties 文件中设置“customBuildCallbacks=true”。
See also the Eclipse help page
另请参阅Eclipse 帮助页面
回答by Rob Ottaway
You can have a separate ant build file for these tasks. Thats all you need.
您可以为这些任务使用单独的 ant 构建文件。这就是你所需要的。