开发者

Java & Google Protocol Buffers: How do I make the jar?

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.

./protoc <params>

I need a jar, because this needs jar: http://code.google.com/p/开发者_Go百科protoclipse/


You can download the required jar from maven central here. Click on the link corresponding to Binary download


Another option is to compile the jar yourself.

To do this you need maven. Download link: 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.

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 java that contains a README (with detailed instruction on what you can do). Another important folder is the src folder, it must contain the binary "protocol buffers compiler" protoc.exe in order to generate the .jar file. So on windows you can download protoc.exe from the protobuf download page and copy it in the src folder. If you run on linux you will have to compile it yourself.

Once protoc.exe is in the src folder, you can run 'mvn package' in the java folder. When the command finishes a new folder called target will appear in the java folder. There is the .jar file that you need.


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

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.

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)


Thats the compiler. The details for generating the jar files are here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜