Download file（https://developers.google.com/protocol-buffers/docs/downloads）and extract to a local folder.
Confirm installed GCC（gcc can be entered in the terminal - -version test）
Switch to protobuf folder.
To build and install Protocol Buffer runtime and the Protocol Buffer compiler (protoc) execute the following:
$ make check
$ make install
"make install" may require superuser privileges.
Hint on install location
By default, the package will be installed to /usr/local. However, on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH. You can add it, but it may be easier to just install to /usr instead. To do this, invoke configure as follows:
If you already built the package with a different prefix, make sure to run "make clean" before building again.
All executed and then enter protoc --version check whether the installation was successful.
2. Compiling Protobuf of .proto
If your proto files stored in the $ SRC_DIR Below, you also want to generate files in the same directory, you can use the following command:
protoc -I=$SRC_DIR --cpp_out=$DST_DIR $SRC_DIR/addressbook.proto
$ cd /usr/local/protobuf/bin
$ sudo ./protoc -I=/Users/zhangsr/Desktop/work/protobuf/
3. Building the Java Protocol Buffers library
The Protocol Buffers build is managed using Maven.
To the installation directory under protobuf-2.6.1/java, execute maven command:
mvn package jar:jar
then will generate target protobuf-java-2.6.1.jar
To reference it for dependency resolution, you would specify it as:
转载请并标注: “本文转载自 linkedkeeper.com ”