用于构建协议缓冲区文件的 Ant 目标
谁能告诉我如何编写 ant 规则(build.xml
)来从 .proto 文件创建 .jar 文件?
基本上,我已经编写了一个功能性的example.proto
,并且我可以使用命令行protoc
来输出java文件。但我想要一个 ant 规则来自动执行上述过程,作为我构建的一部分。有人可以分享一个代码片段作为起点吗?
Can anyone show me how to write ant rules (build.xml
) for creating a .jar file from a .proto file?
Basically, I have written a functional example.proto
and I can use the command line protoc
to output java files. But I want an ant rule to automate the above process as part of my build. Can someone share a code snippet for a starting point?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道这个问题很古老,但它仍然是 Google 上“ant protoc”的热门搜索之一。
我很失望找不到 protoc 的 ant 任务,所以我写了自己的: https://github .com/okorz001/ant-protoc
目前它相当原始,但它支持嵌套文件集,这是我无法弄清楚如何使用 exec hacks 来实现的。 (我绝不是蚂蚁专家。)任务只执行protoc;您将需要使用 ant 的库存 javac 和 jar 任务来生成 jar。
I know this question is ancient, but it is still one of the top hits on Google for "ant protoc".
I was disappointed that I could not find an ant task for protoc, so I wrote my own: https://github.com/okorz001/ant-protoc
It is fairly primitive at the moment, but it supports nested filesets which was something I could not figure out how to do with exec hacks. (I am by no means an ant expert.) The task only executes protoc; you will need to use ant's stock javac and jar tasks in order to produce a jar.
Proto编译也可以通过ant exec来完成。
Proto compilation can also be done through ant exec.
听起来您需要 Ant Exec 任务来执行二进制文件以创建来自
.proto
文件的.java
。然后,Javac 任务 将编译这些任务和 Jar 任务 构建您的.jar
文件。您如何将所有这些联系在一起? 本教程介绍 Ant以及如何利用上述任务。
It sounds like you need the Ant Exec task to execute the binary to create the
.java
from the.proto
files. The Javac task will then compile these and the Jar task builds your.jar
file.How do you tie all this together ? This tutorial introduces Ant and how to make use of tasks like the above.
以下是我将
protoc
合并到项目中所做的工作。理想情况下,我会使用
但是将.proto
文件与其.java
文件关联起来并不简单,因此与此同时,每次protoc
运行时我只需触摸一个标记文件。关键是
任务允许您根据两组文件的相对年龄设置属性(如果 from 早于 to,则为 true,否则为 false)。Here is what I've done to incorporate
protoc
into a project. Ideally I'd use a<mapper>
but associating.proto
files with their.java
files isn't trivial, so in the meantime I just touch a marker file every timeprotoc
runs.The key is the
<uptodate>
task which lets you set a property based on the relative ages of two sets of files (true if from is older than to, false otherwise).