1.下載下傳:
https://github.com/google/protobuf/releases
從網上下載下傳protoc-3.6.1-win32.zip和protobuf-java-3.6.1.zip。
采用maven打包,如果PC上未安裝maven,去下載下傳:
http://maven.apache.org/download.cgi
安裝maven,解壓配置環境變量即可。
maven預設的本地倉庫在C槽,如果不想放置在C槽,可以修改maven的配置檔案,apache-maven-3.5.4\conf下的settings.xml
<localRepository>D:\maven\repository</localRepository>
2.編譯
将這兩個檔案解壓,注意閱讀protobuf-java-3.6.1\protobuf-3.6.1下的README.md和protobuf-java-3.6.1\protobuf-3.6.1\java下的README.md兩個檔案,根據提示,将protoc.exe放置在protobuf-java-3.6.1\protobuf-3.6.1\src下;
You will need to place the protoc executable in ../src. (If you built it yourself, it should already be there.)
cmd,執行mvn package
稍等片刻,等待打包完成,完成後的jar包會放在protobuf-java-3.6.1\protobuf-3.6.1\java\core\target下;
The .jar will be placed in the "target" directory.
3.編譯問題
剛開始下載下傳後,安裝maven,執行mvn package,報錯,原因是依賴的jar包從maven中央倉庫擷取不到,搞不清楚是網絡的原因還是去國外被牆的原因,找了好多部落格,資料,最後添加了mirror和profile後,終于編譯完成。
<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>
<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>
4.參考資料
http://www.cnblogs.com/learn21cn/p/6213372.html