Ant task to create java stub from .proto files in all platforms

535 views
Skip to first unread message

Prakash Rao

unread,
Aug 10, 2010, 11:34:19 AM8/10/10
to Protocol Buffers, prakash...@gmail.com, prakash_rao...@hotmail.com
Hi,
Is there a way to automate java stub creation from .proto files using
ant task in all platforms? And can this be done without using
protoc.exe, which is platform specific?

I saw the below ant task and it uses protoc.exe, which is only for
windows.

<exec executable="protoc">
<arg value="--java_out=outdir" />
<arg value="--proto_path=srcdir" />
<arg value="srcdir/path/to/input.proto" />
</exec>

And has any one tried this (or any other) ant task in windows/cygwin
to generate java stub from .proto files?

Regards,
Prakash

Josh Hartman

unread,
Aug 10, 2010, 2:55:52 PM8/10/10
to Prakash Rao, Protocol Buffers, prakash_rao...@hotmail.com
Actually, I'm going to have to address this pretty soon for my company as well. The biggest problem is compatibility between the different OSes. We don't have to worry about Windows, but we will have to support OSX, Linux, and probably Solaris for building .proto files. With static linking it's definitely possible to reduce the number of dependencies for the binary as shown on OSX below. I don't know how far we can go with static linking - I wasn't able to statically link libz which is a bit surprising. I think the correct solution will be to package 3 different binaries into our build system, switch on the OS, and invoke the proper protoc. I wish Google had written protoc in something like Python or Java rather than C++ to circumvent this problem, but I really can't complain about free, high quality software.

otool -L `which protoc`
/usr/local/bin/protoc:
/usr/local/lib/libprotobuf.4.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/local/lib/libprotoc.4.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)

otool -L src/protoc 
src/protoc:
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.5)



--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Kenton Varda

unread,
Aug 10, 2010, 5:43:39 PM8/10/10
to Prakash Rao, Protocol Buffers, prakash_rao...@hotmail.com
On Tue, Aug 10, 2010 at 8:34 AM, Prakash Rao <prakash...@gmail.com> wrote:
I saw the below ant task and it uses protoc.exe, which is only for
windows.

protoc runs on all platforms, not just windows.  You have to compile it from sources on other platforms.
Message has been deleted

Prakash Rao

unread,
Aug 12, 2010, 7:45:45 AM8/12/10
to Protocol Buffers
Yes, I agree to what you are saying Josh. I was looking something
similar to wsdl2java (purely java) which is platform independent. I'm
not sure whether this is something going to come in future versions.

I tried the ant task which i listed above and it worked in windows/
cygwin.

Thanks a lot Josh & Kenton.

Regards,
Prakash

On Aug 11, 2:43 am, Kenton Varda <ken...@google.com> wrote:
Reply all
Reply to author
Forward
0 new messages