Copilot commented on code in PR #3789:
URL: https://github.com/apache/thrift/pull/3789#discussion_r3917698041


##########
lib/java/README.md:
##########
@@ -209,6 +209,79 @@ gradle 
-Pmaven-repository-url=https://my.company.com/service/local/staging/deplo
 ```
 
 
+Using Thrift in Maven Projects
+=============================
+
+To compile Thrift IDL (`.thrift`) files in a Maven application, use 
`exec-maven-plugin` to execute the `thrift` compiler during the 
`generate-sources` phase, together with `build-helper-maven-plugin` to register 
the generated source directory with the Java compiler:
+
+```xml
+<project>
+  <!-- ... -->
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.thrift</groupId>
+      <artifactId>libthrift</artifactId>
+      <version>${thrift.version}</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <!-- 1. Generate Java sources from Thrift IDL files -->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
+        <version>3.5.0</version>
+        <executions>
+          <execution>
+            <id>generate-thrift-sources</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>exec</goal>
+            </goals>
+            <configuration>
+              <executable>thrift</executable>
+              <arguments>
+                <argument>-r</argument>
+                <argument>--gen</argument>
+                <argument>java</argument>
+                <argument>-out</argument>
+                
<argument>${project.build.directory}/generated-sources/thrift</argument>
+                
<argument>${project.basedir}/src/main/thrift/service.thrift</argument>
+              </arguments>
+            </configuration>

Review Comment:
   The documented `exec-maven-plugin` invocation doesn’t pass any `-I` include 
path (or set a working directory), so any `include "..."` statements in 
`service.thrift` may fail depending on the Maven execution directory. Adding an 
explicit include directory (and/or setting `workingDirectory`) makes the 
example work more reliably.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to