Java Proto Names

Names that are generated by the immutable API.

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.

NOTE: The java_package and java_alt_api_package options are interpreted relative to the API indicated by java_api_version. For example, if java_api_version is 1, then the proto1 package will be java_package and the proto2 package (the “alternative” API) will be java_alt_api_package. And if java_api_version is 2, then java_package determines the proto2 package and java_alt_api_package determines the proto1 package.

Immutable API Message Names

The names for protos generated by the immutable API (java_proto_library BUILD target) are listed in the following table.

java_api_versionjava_multiple_filesjava_alt_api_packagejava_packagejava_outer_classnameGenerated full message name
1trueNot definedNot$package.proto2api.$message
1trueNot definedDefined$java_package.proto2api.$message
1falseDefined-Not defined$java_alt_api_package.$derived_outer_class.$message
1falseNot definedNot definedNot$package.proto2api.$derived_outer_class.$message
1falseNot definedNot$package.proto2api.$java_outer_classname.$message
1falseNot definedDefinedNot defined$java_package.proto2api.$derived_outer_class.$message
1falseNot definedDefinedDefined$java_package.proto2api.$java_outer_classname.$message
2false-Not definedNot$package.$derived_outer_class.$message
2false-DefinedNot defined$java_package.$derived_outer_class.$message


  • - means either setting or not setting the option will not change the generated full message name.

  • $message is the actual name of the proto message.

  • $package is the name of the proto package. This is the name specified by the package directive in the proto file, which is usually at the top of the file.

  • $derived_outer_class is 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 is foo_bar.proto, the $derived_outer_class value is FooBar.

    If the generated class name would be the same as one of the messages defined in the proto file, derived_outer_class has OuterClass appended to it. For example, if the proto is foo_bar.proto and contains a FooBar message, the $derived_outer_class value is FooBarOuterClass. 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 $names are 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.