Skip to content

Commit 6992567

Browse files
committed
Examples fat JARs
Adding tasks for creating executable jar's for the examples. The gradle task `buildExamples` will output fat jar's for each of the examples, which can be later run with ``` java -jar <Example>.jar ```
1 parent 92b05bd commit 6992567

File tree

3 files changed

+185
-12
lines changed

3 files changed

+185
-12
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ buildscript {
2323
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0")
2424
classpath("org.mozilla.rust-android-gradle:plugin:0.9.6")
2525
classpath("com.android.tools.build:gradle:7.4.2")
26+
classpath("com.gradleup.shadow:shadow-gradle-plugin:9.0.0-beta6")
2627
}
2728
}
2829

examples/README.md

Lines changed: 158 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,73 @@
1-
# Zenoh Kotlin examples
1+
# Zenoh Java examples
22

33
----
44

55
## Start instructions
66

7+
For running the examples, there are two approaches. Either you run the gradle example task with the syntax `gradle <example> --args="<arguments>"` or you can build fat JARs the examples through the task `gradle buildExamples`.
8+
9+
While both are valid, in this document we'll follow the second approach; when running `gradle buildExamples`, all the JARs will be located under `/examples/build/libs`, which can later be executed
10+
11+
```bash
12+
java -jar <Example>.jar <arguments>
13+
```
14+
15+
for instance
16+
717
```bash
8-
./gradle <example>
18+
java -jar ZPub.jar -h
919
```
1020

11-
:warning: Passing arguments to these examples has not been enabled yet for this first version. Altering the Zenoh
12-
configuration for these examples must be done programmatically. :warning:
21+
will return
22+
23+
```bash
24+
Usage: ZPub [-hV] [--no-multicast-scouting] [-a=<attachment>] [-c=<configFile>]
25+
[-k=<key>] [-m=<mode>] [-v=<value>] [-e=<connect>[,
26+
<connect>...]]... [-l=<listen>[,<listen>...]]...
27+
Zenoh Pub example
28+
-a, --attach=<attachment>
29+
The attachments to add to each put. The key-value pairs
30+
are &-separated, and = serves as the separator
31+
between key and value.
32+
-c, --config=<configFile>
33+
A configuration file.
34+
-e, --connect=<connect>[,<connect>...]
35+
Endpoints to connect to.
36+
-h, --help Show this help message and exit.
37+
-k, --key=<key> The key expression to write to [default:
38+
demo/example/zenoh-java-pub].
39+
-l, --listen=<listen>[,<listen>...]
40+
Endpoints to listen on.
41+
-m, --mode=<mode> The session mode. Default: peer. Possible values:
42+
[peer, client, router].
43+
--no-multicast-scouting
44+
Disable the multicast-based scouting mechanism.
45+
-v, --value=<value> The value to write. [default: 'Pub from Java!']
46+
-V, --version Print version information and exit.
47+
```
48+
49+
The connect and listen parameters (that are common to all the examples) accept multiple repeated inputs.
50+
For instance:
51+
52+
```bash
53+
java -jar ZPub.jar -l tcp/localhost:7447 -l tcp/localhost:7448 -l tcp/localhost:7449
54+
```
55+
56+
There is the possibility to provide a Zenoh config file as follows
57+
58+
```bash
59+
java -jar ZPub.jar -c path/to/config.json5
60+
```
61+
62+
In that case, any other provided configuration parameters through the command line interface will not be taken into consideration.
63+
64+
One last comment regarding Zenoh logging for the examples, logs from the native library can be enabled through the environment variable `RUST_LOG` as follows:
65+
66+
```bash
67+
RUST_LOG=<level> java -jar ZPub.jar
68+
```
69+
70+
where `<level>` is the log filter (for instance `debug`, `warn`, `error`... (see the [Rust documentation](https://docs.rs/env_logger/latest/env_logger/#enabling-logging))).
1371
1472
----
1573
@@ -23,7 +81,13 @@ The path/value will be received by all matching subscribers, for instance the [Z
2381
Usage:
2482
2583
```bash
26-
./gradle ZPub
84+
java -jar ZPub.jar
85+
```
86+
87+
or
88+
89+
```bash
90+
java -jar ZPub.jar -k demo/example/test -v "hello world"
2791
```
2892
2993
### ZSub
@@ -35,7 +99,13 @@ the subscriber's key expression, and will print this notification.
3599
Usage:
36100
37101
```bash
38-
./gradle ZSub
102+
java -jar ZSub.jar
103+
```
104+
105+
or
106+
107+
```bash
108+
java -jar ZSub.jar -k demo/example/test
39109
```
40110
41111
### ZGet
@@ -45,7 +115,13 @@ The queryables with a matching path or selector (for instance [ZQueryable](#zque
45115
will receive this query and reply with paths/values that will be received by the query callback.
46116
47117
```bash
48-
./gradle ZGet
118+
java -jar ZGet.jar
119+
```
120+
121+
or
122+
123+
```bash
124+
java -jar ZGet.jar -s demo/example/get
49125
```
50126
51127
### ZPut
@@ -56,7 +132,13 @@ The path/value will be received by all matching subscribers, for instance the [Z
56132
Usage:
57133
58134
```bash
59-
./gradle ZPut
135+
java -jar ZPut.jar
136+
```
137+
138+
or
139+
140+
```bash
141+
java -jar ZPut.jar -k demo/example/put -v 'Put from Java!'
60142
```
61143
62144
### ZDelete
@@ -66,7 +148,13 @@ Performs a Delete operation into a path/value into Zenoh.
66148
Usage:
67149
68150
```bash
69-
./gradle ZDelete
151+
java -jar ZDelete.jar
152+
```
153+
154+
or
155+
156+
```bash
157+
java -jar ZDelete.jar -k demo/example/delete
70158
```
71159
72160
### ZQueryable
@@ -78,7 +166,13 @@ with a selector that matches the key expression, and will return a value to the
78166
Usage:
79167
80168
```bash
81-
./gradle ZQueryable
169+
java -jar ZQueryable.jar
170+
```
171+
172+
or
173+
174+
```bash
175+
java -jar ZQueryable.jar -k demo/example/query
82176
```
83177
84178
### ZPubThr & ZSubThr
@@ -90,11 +184,63 @@ put operations and a subscriber receiving notifications of those puts.
90184
Subscriber usage:
91185
92186
```bash
93-
./gradle ZSubThr
187+
java -jar ZSubThr.jar
94188
```
95189
96190
Publisher usage:
97191
98192
```bash
99-
./gradle ZPubThr
193+
java -jar ZPubThr.jar <payload_size>
194+
```
195+
196+
### ZPing & ZPong
197+
198+
Latency tests
199+
200+
```bash
201+
java -jar ZPing.jar
202+
```
203+
204+
```bash
205+
java -jar ZPong.jar
206+
```
207+
208+
### ZScout
209+
210+
A scouting example. Will show information from other nodes in the Zenoh network.
211+
212+
```bash
213+
java -jar ZScout.jar
214+
```
215+
216+
### Liveliness examples
217+
218+
#### ZLiveliness
219+
220+
The ZLiveliness example, it just announces itself to the Zenoh network by default to the key expression `group1/zenoh-java`.
221+
222+
Usage:
223+
224+
```bash
225+
java -jar ZLiveliness
226+
```
227+
228+
It can be used along with the following liveliness examples:
229+
230+
#### ZGetLiveliness
231+
232+
Gets the liveliness tokens, by default to `group1/zenoh-java`.
233+
234+
Usage:
235+
236+
```bash
237+
java -jar ZGetLiveliness
238+
```
239+
240+
#### ZSubLiveliness
241+
242+
Subscribes to liveliness events:
243+
244+
```bash
245+
java -jar ZSubLiveliness
100246
```

examples/build.gradle.kts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
// ZettaScale Zenoh Team, <[email protected]>
1313
//
1414

15+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
16+
1517
plugins {
1618
kotlin("jvm")
1719
kotlin("plugin.serialization") version "1.9.0"
20+
id("com.gradleup.shadow")
1821
}
1922

2023
kotlin {
@@ -50,6 +53,29 @@ tasks {
5053
"ZSubThr"
5154
)
5255

56+
examples.forEach { example ->
57+
register<ShadowJar>("${example}Jar") {
58+
group = "build"
59+
description = "Build a fat JAR for the $example example"
60+
from(sourceSets["main"].output)
61+
manifest {
62+
attributes["Main-Class"] = "io.zenoh.${example}"
63+
}
64+
configurations.empty()
65+
configurations.add(project.configurations.getByName("runtimeClasspath"))
66+
67+
archiveBaseName.set(example)
68+
archiveVersion.set("")
69+
archiveClassifier.set("")
70+
}
71+
}
72+
73+
register("buildExamples") {
74+
group = "build"
75+
description = "Build all fat JARs for the Zenoh Java examples"
76+
dependsOn(examples.map { "${it}Jar" })
77+
}
78+
5379
examples.forEach { example ->
5480
register(example, JavaExec::class) {
5581
dependsOn("CompileZenohJNI")

0 commit comments

Comments
 (0)