Simplified java binding example
This commit is contained in:
@@ -28,13 +28,13 @@
|
||||
|
||||
import zerotier.*;
|
||||
|
||||
public class MyClass {
|
||||
public class ExampleApp {
|
||||
|
||||
public native int loadsymbols();
|
||||
public native void startOneService();
|
||||
|
||||
static {
|
||||
System.load("/Users/joseph/op/zt/libzt/build/darwin/libzt.so");
|
||||
System.loadLibrary("zt");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
18
examples/bindings/java/Makefile
Normal file
18
examples/bindings/java/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
OSTYPE=$(shell uname -s | tr '[A-Z]' '[a-z]')
|
||||
BUILD=build/$(OSTYPE)
|
||||
|
||||
ifeq ($(OSTYPE),darwin)
|
||||
SHARED_LIB=libzt.dylib
|
||||
endif
|
||||
ifeq ($(OSTYPE),linux)
|
||||
SHARED_LIB=libzt.so
|
||||
endif
|
||||
|
||||
example_java_app:
|
||||
javac *.java
|
||||
|
||||
copy_dynamic_lib:
|
||||
cp ../../../$(BUILD)/$(SHARED_LIB) .
|
||||
|
||||
clean:
|
||||
-find . -type f \( -name '*.class' \) -delete
|
||||
@@ -1,9 +1,14 @@
|
||||
Java Examples
|
||||
======
|
||||
## ZeroTier with Java via JNI
|
||||
***
|
||||
|
||||
`make shared_jni_lib SDK_JNI=1 SDK_IPV4=1`
|
||||
To get this example project to work, do the following:
|
||||
|
||||
Uses API described in [api/java/README.md]
|
||||
- Copy `src/ZeroTier.java` into `your_project/src/zerotier`
|
||||
- Copy `src/Address.java` into `your_project/src/zerotier`
|
||||
- Copy `libzt.jnilib` or `libzt.so` from `build/` into `your_project/lib`
|
||||
- From libzt main directory, build shared library: `make shared_jni_lib`
|
||||
- Copy the resultant dynamic library (`*.so` or `*.dylib`) from `build/` to this current directory
|
||||
- Change to this directory and `make example_java_app`
|
||||
- Run: `java -cp "." ExampleApp`
|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
Upon execution, it will load the libzt dynamic library via the `loadLibrary` method and begin generating an identity.
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="/Users/joseph/op/zt/libzt"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/Users/joseph/op/zt/libzt/examples/java/ZeroTierHelloWorld">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="."/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ZeroTierHelloWorld</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,11 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -1,2 +0,0 @@
|
||||
ZeroTierSDK Java API
|
||||
======
|
||||
@@ -24,6 +24,8 @@
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
package zerotier;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -24,6 +24,10 @@
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
package zerotier;
|
||||
|
||||
//import zerotier.*;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
Reference in New Issue
Block a user