+++ title = "Java Proto Names" weight = 655 linkTitle = "Generated Proto Names" description = "Names that are generated by the immutable API." type = "docs" +++
This document contains information on what the fully-qualified Java name of a proto is, based on the different proto options. This name corresponds to the package you need to import to use that message.
The names for protos generated by the immutable API (java_proto_library BUILD
target) are listed in the following table.
| java_api_version | java_multiple_files | java_alt_api_package | java_package | java_outer_classname | Generated full message name |
|---|---|---|---|---|---|
| 1 | true | Defined | - | $java_alt_api_package.$message |
|
| 1 | true | Not defined | Not defined | com.google.protos.$package.proto2api.$message |
|
| 1 | true | Not defined | Defined | $java_package.proto2api.$message |
|
| 1 | false | Defined | - | Not defined | $java_alt_api_package.$derived_outer_class.$message |
| 1 | false | Defined | - | Defined | $java_alt_api_package.$java_outer_classname.$message |
| 1 | false | Not defined | Not defined | Not defined | com.google.protos.$package.proto2api.$derived_outer_class.$message |
| 1 | false | Not defined | Not defined | Defined | com.google.protos.$package.proto2api.$java_outer_classname.$message |
| 1 | false | Not defined | Defined | Not defined | $java_package.proto2api.$derived_outer_class.$message |
| 1 | false | Not defined | Defined | Defined | $java_package.proto2api.$java_outer_classname.$message |
| 2 | true | - | Not defined | - | com.google.protos.$package.$message |
| 2 | true | - | Defined | - | $java_package.$message |
| 2 | false | - | Not defined | Not defined | com.google.protos.$package.$derived_outer_class.$message |
| 2 | false | - | Not defined | Defined | com.google.protos.$package.$java_outer_classname.$message |
| 2 | false | - | Defined | Not defined | $java_package.$derived_outer_class.$message |
| 2 | false | - | Defined | Defined | $java_package.$java_outer_classname.$message |
Legend
-
- means either setting or not setting the option will not change the generated full message name.
-
$messageis the actual name of the proto message. -
$packageis the name of the proto package. This is the name specified by thepackagedirective in the proto file, which is usually at the top of the file. -
$derived_outer_classis a name generated from the proto file name. Generally it's computed by removing punctuation from the file name and converting it to CamelCase. For example, if the proto isfoo_bar.proto, the$derived_outer_classvalue isFooBar.If the generated class name would be the same as one of the messages defined in the proto file,
derived_outer_classhasOuterClassappended to it. For example, if the proto isfoo_bar.protoand contains aFooBarmessage, the$derived_outer_classvalue isFooBarOuterClass. The same is true when using the v1 API, whether or not the class name would be the same as one of the messages defined. -
All other
$namesare the values of the corresponding proto2 file options defined in the proto file.
The recommended option to use is:
option java_multiple_files = true;With java_multiple_files = true, the generated Java class for each message
will be placed in a separate .java file. This makes it much easier to move
messages from one .proto file to another. There is also an outer Java class
generated for the .proto file itself. (The legend above explains how this
outer class name is generated.)
The java_api_version option defaults to 2, but you can manually set it to
1 when necessary.