1. Preparatory work
Need to download the corresponding file on GitHub, address https://github.com/google/protobuf/releases
Protobuf has a lot of different language versions, because we need a jar file, so choose Java version to download. The following examples are illustrated in version 3.1.0.
If it is compiled in the linux64 environment, you can choose the following two files, the first equivalent of the Java distribution version of the source file, the second is a compiled PROTOC program files (if you want to compile Protobuf program files, refer to the previous article Protobuf compiled installation).
- Protobuf-java-3.1.0.tar.gz
- Protoc-3.1.0-linux-x86_64.zip
If you choose to compile in the Windows environment, choose the following two files, again, the first equivalent of the Java distribution version of the source file, the second is a compiled Protoc program file, but Windows under the program version is currently only 32 bits.
- Protobuf-java-3.1.0.zip
- Protoc-3.1.0-win32.zip
2. Compiling
1> in a Linux environment ( need to install Maven in advance)
Unzip the above two files, and then copy the PROTOC Program files extracted from protoc-3.1.0-linux-x86_64.zip to the extracted files directory . the corresponding position of the protobuf-java-3.1.0.
Note the location is very important in the following two folders
Below the SRC directory, put a PROTOC program file directly
A PROTOC program file is also placed in the Core/src folder under the Java folder
After that,CD to the Java folder described above , run the following command directly
MVN Package
The protobuf-java-3.1.0.jar file is generated under the Core/target folder under the Java folder
2> under Windows , with the same location where the files are placed in Linux, you need to place the Protoc.exe program files and compile them directly with the Eclipse program .
Right-click the Pom.xml file under the Java folder
3. Other instructions
To speed up Maven's compilation, you can change the source of Maven to a domestic
Eclpse can click on the "Window" menu-"Preferences"-"maven"-"User Settings", in the Maven storage location. Add a settings.xml file to the M2 folder
similar to Linux, add the settings.xml file directly to the. M2 folder
<Settingsxsi:schemalocation= "http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <Mirrors> <!--Mirror | Specifies a repository mirror site to use instead of a given repository. The Repository that | This mirror serves have an ID, that matches, the mirrorof element of this mirror. IDs is used | For inheritance and direct lookup purposes, and must is unique across the set of mirrors. | - <Mirror> <ID>Alimaven</ID> <mirrorof>Central</mirrorof> <name>Aliyun maven</name> <URL>http://maven.aliyun.com/nexus/content/groups/public/</URL> </Mirror> <Mirror> <ID>Aliyunpublic</ID> <name>Aliyunpublic</name> <URL>http://maven.aliyun.com/nexus/content/groups/public/</URL> <mirrorof>Public</mirrorof> </Mirror> <Mirror> <ID>Centralmaven</ID> <mirrorof>Centralmaven</mirrorof> <name>Centralmaven</name> <URL>http://central.maven.org/maven2/</URL> </Mirror> </Mirrors> <Profiles> < Profile> <ID>Default</ID> <repositories> <Repository> <ID>Nexus</ID> <name>Local private Nexus</name> <URL>http://maven.aliyun.com/nexus/content/repositories/central/</URL> <releases> <enabled>True</enabled> </releases> <Snapshots> <enabled>False</enabled> </Snapshots> </Repository> </repositories> <pluginrepositories> <pluginrepository> <ID>Nexus</ID> <name>Local private Nexus</name> <URL>http://maven.aliyun.com/nexus/content/repositories/central/</URL> <releases> <enabled>True</enabled> </releases> <Snapshots> <enabled>False</enabled> </Snapshots> </pluginrepository> </pluginrepositories> </ Profile> </Profiles></Settings>
A few of the addresses are similar, can be used, can be casually changed position, not fixed in a place, here is just an example.
Compiling the Protobuf jar file