From 7d55040eebab0f2345e6d73905137a030bef35bb Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Thu, 12 Apr 2018 17:58:55 -0700 Subject: Cleanup + documentation for Java Lite runtime. --- java/README.md | 81 +++++++++---- java/lite.md | 50 ++++++++ java/lite/generate-sources-build.xml | 20 ---- java/lite/generate-test-sources-build.xml | 43 ------- java/lite/pom.xml | 185 ------------------------------ java/pom.xml | 3 - 6 files changed, 111 insertions(+), 271 deletions(-) create mode 100644 java/lite.md delete mode 100644 java/lite/generate-sources-build.xml delete mode 100644 java/lite/generate-test-sources-build.xml delete mode 100644 java/lite/pom.xml (limited to 'java') diff --git a/java/README.md b/java/README.md index 0e0fba64..5e4fb8b4 100644 --- a/java/README.md +++ b/java/README.md @@ -1,17 +1,65 @@ -Protocol Buffers - Google's data interchange format -=================================================== - -[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf) +# Protocol Buffers - Google's data interchange format Copyright 2008 Google Inc. -This directory contains the Java Protocol Buffers runtime library. +https://developers.google.com/protocol-buffers/ + +## Use Java Protocol Buffers + +To use protobuf in Java, first obtain the protocol compiler (a.k.a., protoc, +see instructions in the toplevel [README.md](../README.md)) and use it to +generate Java code for your .proto files: + + $ protoc --java_out=${OUTPUT_DIR} path/to/your/proto/file + +Include the generated Java files in your project and add a dependency on the +protobuf Java runtime. If you are using Maven, use the following: + +```xml + + com.google.protobuf + protobuf-java + 3.5.1 + +``` + +Make sure the version number of the runtime matches (or is newer than) the +version number of the protoc. + +If you want to use features like protobuf JsonFormat, add a dependency on the +protobuf-java-util package: + +```xml + + com.google.protobuf + protobuf-java-util + 3.5.1 + +``` + +### Use Java Protocol Buffers on Android + +For Android users, it's recommended to use protobuf Java Lite runtime because +of its smaller code size. Java Lite runtime also works better with Proguard +because it doesn't rely on Java reflection and is optimized to allow as much +code stripping as possible. You can following these [instructions to use Java +Lite runtime](lite.md). + +### Use Java Protocol Buffers with Bazel + +Bazel has native build rules to work with protobuf. For Java, you can use the +`java_proto_library` rule for server and the `java_lite_proto_library` rule +for Android. Check out [our build files examples](../examples/BUILD) to learn +how to use them. + +## Build from Source -Installation - With Maven -========================= +Most users should follow the instructions above to use protobuf Java runtime. +If you are contributing code to protobuf or want to use a protobuf version +that hasn't been officially released yet, you can folllow the instructions +below to build protobuf from source code. -The Protocol Buffers build is managed using Maven. If you would -rather build without Maven, see below. +### Build from Source - With Maven 1) Install Apache Maven if you don't have it: @@ -45,20 +93,15 @@ rather build without Maven, see below. The .jar will be placed in the "target" directory. -The above instructions will install 3 maven artifacts: +The above instructions will install 2 maven artifacts: * protobuf-java: The core Java Protocol Buffers library. Most users only need this artifact. - * protobuf-lite: The lite version of core Java Protobuf Buffers library. It - is a subset of the core library and is used together with - the 'lite' code generator flag to reduce generated code size - for mobile. * protobuf-java-util: Utilities to work with protos. It contains JSON support as well as utilities to work with proto3 well-known types. -Installation - Without Maven -============================ +### Build from Source - Without Maven If you would rather not install Maven to build the library, you may follow these instructions instead. Note that these instructions skip @@ -83,8 +126,7 @@ library (without the util package). 4) Install the classes wherever you prefer. -Compatibility Notice -==================== +## Compatibility Notice * Protobuf minor version releases are backwards-compatible. If your code can build/run against the old version, it's expected to build/run against @@ -118,8 +160,7 @@ Compatibility Notice * Protobuf LITE runtime APIs are not stable yet. They are subject to change even in minor version releases. -Documentation -============= +## Documentation The complete documentation for Protocol Buffers is available via the web at: diff --git a/java/lite.md b/java/lite.md new file mode 100644 index 00000000..84a45ec5 --- /dev/null +++ b/java/lite.md @@ -0,0 +1,50 @@ +# Protocol Buffers - Google's data interchange format + +Copyright 2008 Google Inc. + +https://developers.google.com/protocol-buffers/ + +## Use Protobuf Java Lite Runtime + +Protobuf Java Lite runtime is separated from the main Java runtime because +it's designed/implemented with different constraints. In particular, Java +Lite runtime has a much smaller code size which makes it more suitable to +be used on Android. + +To use Java Lite runtime, you need to install protoc and the protoc plugin for +Java Lite runtime. You can obtain protoc following the instructions in the +toplevel [README.md](../README.md) file. For the protoc plugin, you can +download it from maven: + + https://repo1.maven.org/maven2/com/google/protobuf/protoc-gen-javalite/ + +Choose the version that works on your platform (e.g., on windows you can +download `protoc-gen-javalite-3.0.0-windows-x86_32.exe`), rename it to +protoc-gen-javalite (or protoc-gen-javalite.exe on windows) and place it +in a directory where it can be find in PATH. + +Once you have the protoc and protoc plugin, you can generate Java Lite code +for your .proto files: + + $ protoc --javalite_out=${OUTPUT_DIR} path/to/your/proto/file + +Include the generated Java files in your project and add a dependency on the +protobuf Java runtime. If you are using Maven, use the following: + +```xml + + com.google.protobuf + protobuf-lite + 3.0.1 + +``` + +Make sure the version number of the runtime matches (or is newer than) the +version number of the protoc plugin. The version number of the protoc doesn't +matter and any version >= 3.0.0 should work. + +### Use Protobuf Java Lite Runtime with Bazel + +Bazel has native build rules to work with protobuf. For Java Lite runtime, +you can use the `java_lite_proto_library` rule. Check out [our build files +examples](../examples/BUILD) to learn how to use it. diff --git a/java/lite/generate-sources-build.xml b/java/lite/generate-sources-build.xml deleted file mode 100644 index 89c21c13..00000000 --- a/java/lite/generate-sources-build.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/java/lite/generate-test-sources-build.xml b/java/lite/generate-test-sources-build.xml deleted file mode 100644 index cdd1ee89..00000000 --- a/java/lite/generate-test-sources-build.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/lite/pom.xml b/java/lite/pom.xml deleted file mode 100644 index c902f819..00000000 --- a/java/lite/pom.xml +++ /dev/null @@ -1,185 +0,0 @@ - - - 4.0.0 - - com.google.protobuf - protobuf-parent - 3.0.0 - - - protobuf-lite - bundle - - Protocol Buffers [Lite] - A trimmed-down version of the Protocol Buffers library. - - - - junit - junit - - - org.easymock - easymock - - - org.easymock - easymockclassextension - - - - - ../core - ${core.root}/src/test/proto - - - - ${core.root}/src/main/java - ${core.root}/src/test/java - - - - - maven-antrun-plugin - - - - generate-sources - generate-sources - - - - - - - run - - - - - - generate-test-sources - generate-test-sources - - - - - - - run - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-generated-sources - generate-sources - - add-source - - - - ${generated.sources.lite.dir} - - - - - add-generated-test-sources - generate-test-sources - - add-test-source - - - - ${generated.testsources.lite.dir} - - - - - - - maven-compiler-plugin - - - **/AbstractMessageLite.java - **/AbstractParser.java - **/AbstractProtobufList.java - **/BooleanArrayList.java - **/ByteString.java - **/CodedInputStream.java - **/CodedOutputStream.java - **/DoubleArrayList.java - **/ExtensionLite.java - **/ExtensionRegistryLite.java - **/FieldSet.java - **/FloatArrayList.java - **/GeneratedMessageLite.java - **/IntArrayList.java - **/Internal.java - **/InvalidProtocolBufferException.java - **/LazyFieldLite.java - **/LazyStringArrayList.java - **/LazyStringList.java - **/LongArrayList.java - **/MapEntryLite.java - **/MapFieldLite.java - **/MessageLite.java - **/MessageLiteOrBuilder.java - **/MessageLiteToString.java - **/MutabilityOracle.java - **/NioByteString.java - **/Parser.java - **/PrimitiveNonBoxingCollection.java - **/ProtobufArrayList.java - **/ProtocolStringList.java - **/RopeByteString.java - **/SmallSortedMap.java - **/TextFormatEscaper.java - **/UninitializedMessageException.java - **/UnknownFieldSetLite.java - **/UnmodifiableLazyStringList.java - **/UnsafeByteOperations.java - **/Utf8.java - **/WireFormat.java - - - **/*Lite.java - **/BooleanArrayListTest.java - **/DoubleArrayListTest.java - **/FloatArrayListTest.java - **/IntArrayListTest.java - **/LazyMessageLiteTest.java - **/LiteTest.java - **/LongArrayListTest.java - **/NioByteStringTest.java - **/ProtobufArrayListTest.java - **/UnknownFieldSetLiteTest.java - - - - - - - org.apache.felix - maven-bundle-plugin - true - - - https://developers.google.com/protocol-buffers/ - com.google.protobuf - com.google.${project.artifactId};version=${project.version} - - - - - - - diff --git a/java/pom.xml b/java/pom.xml index c42cae11..f2284918 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -33,8 +33,6 @@ src/test/proto ${project.build.directory}/generated-sources ${project.build.directory}/generated-test-sources - ${project.build.directory}/generated-sources-lite - ${project.build.directory}/generated-test-sources-lite @@ -208,7 +206,6 @@ core - util -- cgit v1.2.3