Skip to content

Commit 834a5a1

Browse files
authored
Fix Java cookbooks (#399)
* Fix Java cookbooks * Fix
1 parent 23feeb6 commit 834a5a1

4 files changed

Lines changed: 31 additions & 74 deletions

File tree

client-sdk/spice-java-sdk-sample/README.md

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,61 +45,12 @@ Spice.ai runtime starting...
4545
In another terminal, compile and run:
4646

4747
```bash
48-
mvn clean compile
49-
_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" \
50-
mvn exec:java -Dexec.mainClass="ai.spice.example.App"
51-
```
52-
53-
Sample build logs:
54-
55-
```text
56-
[INFO] Scanning for projects...
57-
[INFO]
58-
[INFO] ------------------< ai.spice.example:taxi-trips-app >-------------------
59-
[INFO] Building taxi-trips-app 1.0-SNAPSHOT
60-
[INFO] from pom.xml
61-
[INFO] --------------------------------[ jar ]---------------------------------
62-
[INFO]
63-
[INFO] --- clean:3.2.0:clean (default-clean) @ taxi-trips-app ---
64-
[INFO] Deleting /Users/sg/spice/samples/client-sdk/spice-java-sdk-sample/target
65-
[INFO]
66-
[INFO] --- resources:3.3.1:resources (default-resources) @ taxi-trips-app ---
67-
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
68-
[INFO] skip non existing resourceDirectory /Users/sg/spice/samples/client-sdk/spice-java-sdk-sample/src/main/resources
69-
[INFO]
70-
[INFO] --- compiler:3.13.0:compile (default-compile) @ taxi-trips-app ---
71-
[INFO] Recompiling the module because of changed source code.
72-
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
73-
[INFO] Compiling 1 source file with javac [debug target 1.8] to target/classes
74-
[WARNING] bootstrap class path is not set in conjunction with -source 8
75-
not setting the bootstrap class path may lead to class files that cannot run on JDK 8
76-
--release 8 is recommended instead of -source 8 -target 1.8 because it sets the bootstrap class path automatically
77-
[WARNING] source value 8 is obsolete and will be removed in a future release
78-
[WARNING] target value 8 is obsolete and will be removed in a future release
79-
[WARNING] To suppress warnings about obsolete options, use -Xlint:-options.
80-
[INFO] ------------------------------------------------------------------------
81-
[INFO] BUILD SUCCESS
82-
[INFO] ------------------------------------------------------------------------
83-
[INFO] Total time: 0.712 s
84-
[INFO] Finished at: 2024-07-16T12:43:33-07:00
85-
[INFO] ------------------------------------------------------------------------
48+
mvn clean compile exec:exec
8649
```
8750

8851
Sample output:
8952

9053
```text
91-
Picked up _JAVA_OPTIONS: --add-opens=java.base/java.nio=ALL-UNNAMED
92-
[INFO] Scanning for projects...
93-
[INFO]
94-
[INFO] ------------------< ai.spice.example:taxi-trips-app >-------------------
95-
[INFO] Building taxi-trips-app 1.0-SNAPSHOT
96-
[INFO] from pom.xml
97-
[INFO] --------------------------------[ jar ]---------------------------------
98-
[INFO]
99-
[INFO] --- exec:3.3.0:java (default-cli) @ taxi-trips-app ---
100-
[ai.spice.example.App.main()] INFO org.apache.arrow.memory.BaseAllocator - Debug mode disabled. Enable with the VM option -Darrow.memory.debug.allocator=true.
101-
[ai.spice.example.App.main()] INFO org.apache.arrow.memory.DefaultAllocationManagerOption - allocation manager type not specified, using netty as the default type
102-
[ai.spice.example.App.main()] INFO org.apache.arrow.memory.CheckAllocator - Using DefaultAllocationManager at memory-netty/16.1.0/arrow-memory-netty-16.1.0.jar!/org/apache/arrow/memory/netty/DefaultAllocationManagerFactory.class
10354
VendorID tpep_pickup_datetime fare_amount
10455
2 2024-01-14T08:32:55 70.0
10556
1 2024-01-14T08:13:28 70.0
@@ -124,16 +75,7 @@ export SPICE_API_KEY="your_api_key"
12475
The cloud snippet keeps an inline API key placeholder by design. Replace the API key placeholder in `src/main/java/ai/spice/example/Cloud.java` with `${SPICE_API_KEY}`, then run:
12576

12677
```bash
127-
_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" \
128-
mvn exec:java -Dexec.mainClass="ai.spice.example.Cloud"
129-
```
130-
131-
## Note on Java Flags
132-
133-
Apache Arrow Flight requires:
134-
135-
```bash
136-
_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED"
78+
mvn exec:exec -Dexec.mainClass="ai.spice.example.Cloud"
13779
```
13880

13981
## Advanced: Gradle Workflow

client-sdk/spice-java-sdk-sample/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,24 @@
1818
<properties>
1919
<maven.compiler.source>17</maven.compiler.source>
2020
<maven.compiler.target>17</maven.compiler.target>
21+
<exec.mainClass>ai.spice.example.App</exec.mainClass>
2122
</properties>
23+
<build>
24+
<plugins>
25+
<plugin>
26+
<groupId>org.codehaus.mojo</groupId>
27+
<artifactId>exec-maven-plugin</artifactId>
28+
<version>3.6.3</version>
29+
<configuration>
30+
<executable>java</executable>
31+
<arguments>
32+
<argument>--add-opens=java.base/java.nio=ALL-UNNAMED</argument>
33+
<argument>-classpath</argument>
34+
<classpath/>
35+
<argument>${exec.mainClass}</argument>
36+
</arguments>
37+
</configuration>
38+
</plugin>
39+
</plugins>
40+
</build>
2241
</project>

client-sdk/spice-java-sdk-sample/src/main/java/ai/spice/example/Cloud.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public static void main(String[] args) {
1212
try (
1313
SpiceClient client = SpiceClient.builder()
1414
.withApiKey("API_KEY")
15-
.withHttpAddress(URI.create("https://data.spiceai.io"))
16-
.withFlightAddress(URI.create("grpc+tls://flight.spiceai.io:443"))
15+
.withHttpAddress(URI.create("https://us-east-1-prod-aws-data.spiceai.io"))
16+
.withFlightAddress(URI.create("grpc+tls://us-east-1-prod-aws-flight.spiceai.io"))
1717
.build()
1818
) {
1919
FlightStream stream = client.query(

clients/java/pom.xml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,15 @@
4646
<plugin>
4747
<groupId>org.codehaus.mojo</groupId>
4848
<artifactId>exec-maven-plugin</artifactId>
49-
<version>3.0.0</version>
49+
<version>3.6.3</version>
5050
<configuration>
51-
<fork>true</fork>
52-
<mainClass>MessagingServiceApp</mainClass>
53-
<jvmArgs>
54-
<jvmArg>--enable-preview</jvmArg>
55-
<jvmArg>--add-opens=java.base/java.lang=ALL-UNNAMED</jvmArg>
56-
<jvmArg>--add-opens=java.base/java.nio=ALL-UNNAMED</jvmArg>
57-
<jvmArg>--add-opens=java.base/java.lang.reflect=ALL-UNNAMED</jvmArg>
58-
<jvmArg>--add-opens=java.base/java.util=ALL-UNNAMED</jvmArg>
59-
<jvmArg>--add-opens=java.base/sun.nio.ch=ALL-UNNAMED</jvmArg>
60-
<jvmArg>--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED</jvmArg>
61-
</jvmArgs>
51+
<executable>java</executable>
52+
<arguments>
53+
<argument>--add-opens=java.base/java.nio=ALL-UNNAMED</argument>
54+
<argument>-classpath</argument>
55+
<classpath/>
56+
<argument>MessagingServiceApp</argument>
57+
</arguments>
6258
</configuration>
6359
</plugin>
6460
</plugins>

0 commit comments

Comments
 (0)