Protobuf-java maven Configuration
1. Maven Pom Fragment
<!--Protobuf-java for maven plugin Http://stackoverflow.com/questions/1578456/integrate-prot
Ocol-buffers-into-maven2-build Execute failed:java.io.IOException:Cannot Run Program "PROTOC":
Complile and install compiler the PROTOC: # git clone https://github.com/google/protobuf #./autogen.sh #/configure # make && make check # sudo m Ake install after all, compile a proto to java (= = means two minus signs): # protoc-i= $SRC _dir ==java_out= $DST _dir user.proto--> <plugin> <artifactid>maven-
Antrun-plugin</artifactid> <executions> <execution>
<id>generate-sources</id> <phase>generate-sources</phase> <configuration> <tasks> <mkdir dir= "src/main/java/avro/
Channel/protobuf "/> <exec failonerror=" true "executable=" Protoc ">
<arg value= "--java_out=src/main/java/avro/channel/protobuf"/> <arg value= "Src/avro/user.proto"/> </exec> <
/tasks> <sourceRoot>src/main/java/avro/channel/protobuf</sourceRoot> </configuration> <goals> <goal>run< /goal> </goals> </execution> </executions>
;
</plugin> </plugins> </build> <dependencies> <dependency> <grouPid>com.google.protobuf</groupid> <artifactId>protobuf-java</artifactId> < Version>${protobuf-java.version}</version> </dependency> </dependencies>
2. User.proto
Option Java_package = "Avro.channel.protobuf";
Option Java_outer_classname = "Reg";
Message User {
Required String ipaddr = 1;
Optional String cookie = 2;
Optional Int64 token = 3;
}
3. Installation protobuf 1) Download
Https://github.com/google/protobuf/releases
$ wget--no-check-certificate https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
2) Installation
$ TAR-ZXF protobuf-2.6.1.tar.gz
$ cd protobuf-2.6.1/
$/configure $ make
check sudo-make
install
3) under Ubuntu
$ sudo cd/etc/ld.so.conf.d/
$ sudo touch libprotobuf.conf
$ sudo echo "/usr/local/lib" >> libprotobuf.conf
$ sudo ldconfig
4) Inspection
$ protoc--version
Libprotoc 2.6.1