天天看点

protobuf环境准备

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