summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Henry <[email protected]>2023-06-04 15:07:32 -0700
committerJoseph Henry <[email protected]>2023-06-04 15:07:32 -0700
commit356dcd05f664da88b42dab60d56acbac9c5e982f (patch)
tree6f06aab694d1b20480380feefc037e3c80cc7928
parent4aa57d7360c941eba5ab5377311ef660c48f490e (diff)
Update Java example
-rw-r--r--examples/java/Example.java4
-rw-r--r--examples/java/Makefile9
-rw-r--r--examples/java/README.md51
3 files changed, 49 insertions, 15 deletions
diff --git a/examples/java/Example.java b/examples/java/Example.java
index 344c3dd..736496e 100644
--- a/examples/java/Example.java
+++ b/examples/java/Example.java
@@ -5,7 +5,7 @@ import java.math.BigInteger;
import java.net.DatagramPacket;
import java.net.InetAddress;
-public class selftest {
+public class Example {
public static void main(String[] args)
{
if (args.length < 4 || args.length > 5) {
@@ -110,7 +110,7 @@ public class selftest {
/**
* (OPTIONAL) event handler
*/
-class MyZeroTierEventListener implements ZeroTierEventListener {
+class MyZeroTierEventListener implements com.zerotier.sockets.ZeroTierEventListener {
public void onZeroTierEvent(long id, int eventCode)
{
if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_UP) {
diff --git a/examples/java/Makefile b/examples/java/Makefile
deleted file mode 100644
index 4424d0a..0000000
--- a/examples/java/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-all:
- jar xf *.jar libzt.dylib
- javac -cp *.jar Example.java
-
-clean:
- rm -rf *.class
-
-superclean: clean
- rm -rf *.dylib *.so *.jar
diff --git a/examples/java/README.md b/examples/java/README.md
index 870f020..40db2d8 100644
--- a/examples/java/README.md
+++ b/examples/java/README.md
@@ -1,11 +1,54 @@
# Java example
-Build or download the `libzt-${VERSION}.jar`, and copy it to this directory.
+## Build the JAR
+
+From the top-level `libzt` directory:
+
+```
+./build.sh host-jar
+```
+
+Should result in something like:
+
+```
+dist
+└── linux-x64-jar-release
+ └── pkg
+ └── libzt-1.8.10.jar
+```
+
+Copy the JAR to the working directory:
+
+*NOTE: If you've built multiple variants of the JAR such as debug/release or mac/linux you will need to specify their exact path in the following command. If not, you can use the wildcard form:*
+
+
+```
+cp -f dist/*/pkg/*.jar examples/java/libzt.jar
+```
+
+Navigate to the `examples/java` directory and extract the `libzt.so|dylib|dll` dynamic library from the JAR into the working directory:
+
+```
+jar xf *.jar libzt.dylib libzt.so libzt.dll
+```
+
+## Build the example app
+
+```
+javac -cp *.jar Example.java
+```
+
+## Run the example app
+
+```
+java -Djava.library.path=. -cp ".:libzt.jar" Example server id_path 0123456789abcdef 9997
+java -Djava.library.path=. -cp ".:libzt.jar" Example client id_path 0123456789abcdef ip.ip.ip.ip 9997
+```
+
+## Clean
```
-make
-java -cp ".:libzt-${VERSION}.jar" Example server id_path 0123456789abcdef 9997
-java -cp ".:libzt-${VERSION}.jar" Example client id_path 0123456789abcdef ip.ip.ip.ip 9997
+rm -rf *.dylib *.so *.jar *.dll *.class
```
## Links