Wednesday, 15 September 2010

maven - Google Protobuf - Java - Issue in 'import' of proto files in one another -



maven - Google Protobuf - Java - Issue in 'import' of proto files in one another -

i've created sample maven project in java , having below configuration:

i using below maven-antrun-plugin in pom.xml : <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-antrun-plugin</artifactid> <version>1.7</version> <executions> <execution> <id>generate-sources</id> <phase>generate-sources</phase> <configuration> <target> <echo>generate</echo> <path id="proto.path"> <fileset dir="src/main/java/com/xyz/zrtb/simulator/proto"> <include name="**/*.proto" /> </fileset> </path> <pathconvert pathsep=" " property="proto.files" refid="proto.path" /> <exec executable="protoc" failonerror="true"> <arg value="--java_out=src/main/java" /> <arg value="--proto_path=${project.basedir}/src/main/java/com/xyz/zrtb/simulator/proto/" /> <arg line="${proto.files}" /> </exec> </target> <sourceroot>src/</sourceroot> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins>

note: above configuration works fine plain proto files not having 'import' statements or 'objects variables' in message not work file having 'import' statements or 'objects variables'.

below proto files using: a.proto :

option java_package = "com.xyz.zrtb.simulator.protos"; alternative java_outer_classname = "a"; message { optional string id = 1; optional string name = 2; repeated string cat = 4; optional string domain = 3; }

b.proto :

option java_package = "com.xyz.zrtb.simulator.protos"; alternative java_outer_classname = "b"; import "a.proto"; message b { optional string id = 1; optional string name = 2; optional string domain = 3; repeated string cat = 4; optional string page = 5; optional string ref = 6; optional a = 7; }

these proto files in same bundle named com.xyz.zrtb.simulator.proto

below project structure:

myproject |------src/main/java (source folder) |------ com.xyz.zrtb.simulator.proto |------ com.xyz.zrtb.simulator.protos (for generated java files)

above explains structure, error getting while running maven generate-sources given below:

[info] --- maven-antrun-plugin:1.7:run (generate-sources) @ myproject-web --- [info] executing tasks main: [echo] generate [exec] site.proto:13:14: "a" not defined.

i tried lot of options did not work, please help. '--proto-path' problem. i've tried below import statements didn't work:

import "com/xyz/zrtb/simulator/proto/a.proto" import "src/main/java/com/xyz/zrtb/simulator/proto/a.proto" import "myproject/src/main/java/com/xyz/zrtb/simulator/proto/a.proto"

java maven

No comments:

Post a Comment