2018-01-28 13:58:33 +03:00
# TDLib Java example
To run this example, you will need installed JDK >= 1.6.
For Javadoc documentation generation PHP is needed.
2021-12-19 18:10:59 +03:00
You can find complete build instructions for your operating system at https://tdlib.github.io/td/build.html?language=Java.
In general, the build process looks as follows.
2020-08-18 09:51:18 +03:00
TDLib should be prebuilt with JNI bindings and installed to local subdirectory `td/` as follows:
2018-01-28 13:58:33 +03:00
```
2018-01-28 21:13:25 +03:00
cd < path to TDLib sources >
2018-01-28 13:58:33 +03:00
mkdir jnibuild
cd jnibuild
cmake -DCMAKE_BUILD_TYPE=Release -DTD_ENABLE_JNI=ON -DCMAKE_INSTALL_PREFIX:PATH=../example/java/td ..
cmake --build . --target install
```
2019-09-07 02:14:49 +03:00
If you want to compile TDLib for 32-bit/64-bit Java on Windows using MSVC, you will also need to add `-A Win32` /`-A x64` option to CMake.
2018-01-28 13:58:33 +03:00
2021-12-19 18:10:59 +03:00
In Windows, use vcpkg toolchain file by adding parameter -DCMAKE_TOOLCHAIN_FILE=< VCPKG_DIR > /scripts/buildsystems/vcpkg.cmake
2018-03-20 16:48:47 +02:00
2018-01-28 13:58:33 +03:00
Then you can build this example:
```
2018-01-28 21:13:25 +03:00
cd < path to TDLib sources > /example/java
2018-01-28 13:58:33 +03:00
mkdir build
cd build
2018-01-28 21:13:25 +03:00
cmake -DCMAKE_BUILD_TYPE=Release -DTd_DIR=< full path to TDLib sources > /example/java/td/lib/cmake/Td -DCMAKE_INSTALL_PREFIX:PATH=.. ..
2018-01-28 13:58:33 +03:00
cmake --build . --target install
```
2018-03-13 22:45:00 +03:00
Compiled TDLib shared library and Java example after that will be placed in bin/ and Javadoc documentation in `docs/` .
2018-01-28 13:58:33 +03:00
Now you can run Java example:
```
2018-01-28 21:13:25 +03:00
cd < path to TDLib sources > /example/java/bin
2018-03-14 14:50:42 +03:00
java '-Djava.library.path=.' org/drinkless/tdlib/example/Example
2018-01-28 13:58:33 +03:00
```
2021-09-06 13:58:40 +03:00
If you receive "Could NOT find JNI ..." error from CMake, you need to specify to CMake path to the installed JDK, for example, "-DJAVA_HOME=/usr/lib/jvm/java-8-oracle/".
2018-01-28 15:43:04 +03:00
2021-09-06 13:58:40 +03:00
If you receive java.lang.UnsatisfiedLinkError with "Can't find dependent libraries", you may also need to copy some dependent shared OpenSSL and zlib libraries to `bin/` .
2018-03-20 16:48:47 +02:00
2021-12-19 18:10:59 +03:00
Make sure that you compiled the example for the same architecture as your JVM.