Java 和 Google Protocol Buffers:如何制作 jar?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4687069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java & Google Protocol Buffers: How do I make the jar?
提问by NullVoxPopuli
I downloaded the source code (because there is no compiled version), and I compiled it, but it didn't generate a .jar. Instead it made a file that can be executed in a bash/zsh shell.
我下载了源代码(因为没有编译版本),我编译了,但是没有生成.jar。相反,它创建了一个可以在 bash/zsh shell 中执行的文件。
./protoc <params>
I need a jar, because this needs jar: http://code.google.com/p/protoclipse/
我需要一个 jar,因为这需要 jar:http: //code.google.com/p/protoclipse/
采纳答案by Chris Shain
回答by Aravind Yarram
You can download the required jar from maven central here. Click on the link corresponding to Binary download
您可以从这里的 maven central下载所需的 jar 。点击二进制下载对应的链接
回答by Ha11owed
Another option is to compile the jar yourself.
另一种选择是自己编译 jar。
To do this you need maven. Download link: http://maven.apache.org/download.cgi
为此,您需要 Maven。下载链接:http: //maven.apache.org/download.cgi
To "install" you just need to unzip the download to a directory and add that directory to your PATH system variable. Please note that the JAVA_HOME system variable should point to JDK installation folder.
要“安装”,您只需要将下载解压缩到一个目录并将该目录添加到您的 PATH 系统变量中。请注意 JAVA_HOME 系统变量应指向 JDK 安装文件夹。
Alter you did all this you can go with the command line in the protocol buffers source folder. the source folder contains a folder called javathat contains a README(with detailed instruction on what you can do). Another important folder is the srcfolder, it must contain the binary "protocol buffers compiler" protoc.exein order to generate the .jar file. So on windows you can download protoc.exefrom the protobuf download page and copy it in the srcfolder. If you run on linux you will have to compile it yourself.
完成所有这些操作后,您可以使用协议缓冲区源文件夹中的命令行。源文件夹包含一个名为java的文件夹,其中包含一个自述文件(详细说明您可以做什么)。另一个重要的文件夹是src文件夹,它必须包含二进制“协议缓冲区编译器” protoc.exe才能生成 .jar 文件。因此,在 Windows 上,您可以从 protobuf 下载页面下载protoc.exe并将其复制到src文件夹中。如果你在 linux 上运行,你将不得不自己编译它。
Once protoc.exeis in the srcfolder, you can run 'mvn package' in the javafolder. When the command finishes a new folder called target will appear in the java folder. There is the .jar file that you need.
一旦protoc.exe位于src文件夹中,您就可以在java文件夹中运行“ mvn package” 。当命令完成后,一个名为 target 的新文件夹将出现在 java 文件夹中。有您需要的 .jar 文件。
For the lazy like me that just want to see the commands:
对于像我这样只想查看命令的懒人:
maven folder: C:\MyPrograms\apache-maven-3.1.0\
protoc src folder(contains the source code): D:\Downloads\protobuf-2.5.0\
protoc compiler folder (contains protoc.exe): D:\Downloads\protoc-2.5.0-win32\
java jdk: C:\Program Files\Java\jdk1.7.0_21
maven 文件夹:C:\MyPrograms\apache-maven-3.1.0\
protoc src 文件夹(包含源代码):D:\Downloads\protobuf-2.5.0\
protoc 编译器文件夹(包含 protoc.exe):D:\下载\protoc-2.5.0-win32\
java jdk: C:\Program Files\Java\jdk1.7.0_21
SET PATH=%PATH%;C:\MyPrograms\apache-maven-3.1.0\bin
SET JAVA_HOME=C:\Program Files\Java\jdk1.7.0_21
cd D:\Downloads\protobuf-2.5.0\
copy D:\Downloads\protoc-2.5.0-win32\protoc.exe src
cd java
mvn package
NOTE:if you are on linux you will need to replace the copy with a compilation of protoc. also setting the path is most likely not needed or done in a different way.
注意:如果您使用的是 linux,则需要用 protoc 的编译替换副本。也很可能不需要或以不同的方式设置路径。
so instead of:
所以而不是:
copy D:\Downloads\protoc-2.5.0-win32\protoc.exe src
you will have:
你将会拥有:
./configure
make
make check
make install
(just make sure the generated binary is copied in the correct folder)
(只需确保将生成的二进制文件复制到正确的文件夹中)