windows10 下面,编译protobuf-java-3.0.0-beta-1.jar

来源:互联网 发布:js拉链是哪个国家的 编辑:程序博客网 时间:2024/06/01 14:47

其实这个本来已经有的,但是因为一些失误,导致编译花了很长时间,所以打算写下来,也算是给自己一个经验教训

  1. 下载Protocol buffers址:https://github.com/google/protobuf/releases
  2. 这里,我们选择下载java版本,具体文件是:protobuf-java-3.0.0-beta-1.zip
  3. 解压,找到java文件夹并打开这个文件夹
  4. 打开这个java文件夹下的README.md 文件
  5. 于是,看到这样的文件

6. `Installation - With Maven

The Protocol Buffers build is managed using Maven. If you would
rather build without Maven, see below.

1) Install Apache Maven if you don’t have it:

 http://maven.apache.org/

2) Build the C++ code, or obtain a binary distribution of protoc. If
you install a binary distribution, make sure that it is the same
version as this package. If in doubt, run:

 $ protoc --version

You will need to place the protoc executable in ../src. (If you
built it yourself, it should already be there.)

3) Run the tests:

 $ mvn test

If some tests fail, this library may not work correctly on your
system. Continue at your own risk.

4) Install the library into your Maven repository:

 $ mvn install

5) If you do not use Maven to manage your own build, you can build a
.jar file to use:

 $ mvn package

The .jar will be placed in the “target” directory.`

根据上描述,第一步下载maven,下载地址: http://maven.apache.org/
第二步,检查protoc文件的版本,(现在我们来下载这个文件https://github.com/google/protobuf/releases),选择版本:protoc-3.0.0-beta-1-win32.zip,。。。。。也就是在这里,我下载错了版本!!!下载了beta-2-win32,导致我编译了一上午都没有成功!!而且合理使用protoc –version查看版本号的时候,居然都显示的是3.0.0版本!!
另外,这里要求把protoc.exe这个运行文件,放到当前前目录的上一级目录的src文件夹下面 ,../src 其中,两个点代表当前文件夹的上一级目录,../src就表示,先回到当前文件夹的上一级目录,然后再上一级目录下面找到src目录,将protoc.exe这个文件放置到这个src下面,

  1. 下面。来配置maven,http://maven.apache.org
    maven是一个项目管理工具,它具备一种自动理解的功能,基于POM的理念,通常,我们通过pom.xml这个文件,来进行项目的build,reporting等
  2. 下载好maven之后,要设置path变量,但是通常为了这样一个编译操作,不建议去设置环境变量(当然也可以这样做),
  3. 记下来,我们来到第三条提到的java目录下,在cmd窗口下打开这个目录,接下来通过set命令设置maven目录(如果已经在环境变量中配置了maven,则不需要另外设置),命令如下 set path=”你的maven的路径/bin/”,这里的您的maven目录并不包含其子目录,
  4. 接下来,运行下面的这个命令
    mvn test
  5. 等待完成以后(第一次运行可能要很长的时间),在运行
    mvn install
  6. 之后运行
    mvn package

    此时在当前目录下的target目录下,就能看到
    protobuf-java-3.0.0-beta-1.jar这个文件了

0 0