Td: how to use IntelliJ for java example

Created on 4 Jul 2018  ยท  6Comments  ยท  Source: tdlib/td

I finally can build java example. it's cool but how can use IntelliJ to programming and build a project.
I want to use JavaFX and maven in IntelliJ to build a desktop application, can anyone help me?

Most helpful comment

tnx @mincong-h, I run this project on IntelliJ with VM options of Run/Debug configurations.
and in maven, I think maybe need other option to set for compile code but this is not and it's like other projects

All 6 comments

I use IntelliJ to develop Java solution. Once you've built the Java example, you can copy all the Java files *.java into Maven source directory src/main/java. Don't forget the generated one โ€” org.drinkless.tdlib.TdApi.java. Once you've copied everything, the structure looks like:

$ tree src/main/java/
src/main/java/
โ”œโ”€โ”€ yourpackage
โ”‚ย ย  โ”œโ”€โ”€ A.java
โ”‚ย ย  โ”œโ”€โ”€ B.java
โ”‚ย ย  โ””โ”€โ”€ C.java
โ””โ”€โ”€ org
    โ””โ”€โ”€ drinkless
        โ””โ”€โ”€ tdlib
            โ”œโ”€โ”€ Client.java
            โ”œโ”€โ”€ Log.java
            โ”œโ”€โ”€ TdApi.java
            โ””โ”€โ”€ example
                โ””โ”€โ”€ Example.java

You can now develop your own solution as a usual Maven project. However, there's a tricky point for execution. You must include the Telegram Database library (JNI) to run your final JAR:

$ java -Djava.library.path=/path/to/tdlib -jar /path/to/jar

tnx @mincong-h, I don't look to org.drinkless.tdlib folder after the build Java.
it looks like fine but I have two another problem

  1. how to run the project from IntelliJ? I add java.library.path=/Users/peter/Downloads/td/ to VM options of Run/Debug Configurations bug get this error
    Error: Could not find or load main class java.library.path=.Users.peter.Downloads.td.
  2. I use this library for java packager.
    how to add tdlib to it or another library for java packager? JavaFX-maven-plugin can add VM option my question is how to add tdlib to it for all windows

how to run the project from IntelliJ? I add java.library.path=/Users/peter/Downloads/td/ to VM options of Run/Debug Configurations bug get this error
Error: Could not find or load main class java.library.path=.Users.peter.Downloads.td.

The main class should be org.drinkless.tdlib.example.Example.java, where the static method main is defined:

public static void main(String[] args) throws InterruptedException { ... }

I don't use Run/Debug configurations in IntelliJ. I ran the final JAR directly... So I don't know how to configure it.

I use this library for java packager.
how to add tdlib to it or another library for java packager? JavaFX-maven-plugin can add VM option my question is how to add tdlib to it for all windows

Sorry I don't know this one, neither.

I found my mistake, yes I run org.drinkless.tdlib.example.Example.java but must set -Djava.library.path=/Users/peter/Downloads/td/ instead of java.library.path=... but another error happend

Exception in thread "main" java.lang.UnsatisfiedLinkError: no tdjni in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at org.drinkless.tdlib.example.Example.<clinit>(Example.java:58)

I working on mac any idea for this?

can you give me a pom file to compile a jar file?

-Djava.library.path=/Users/peter/Downloads/td/

This path is incorrect. The shared library is stored in /Users/peter/Downloads/td/example/java/bin, which is relevant with the documentation:

Now you can run Java example:

cd <path to TDLib sources>/example/java/bin
java '-Djava.library.path=.' org/drinkless/tdlib/example/Example

For the POM file, you can take a look at Stack Overflow: How can I create an executable JAR with dependencies using Maven?

tnx @mincong-h, I run this project on IntelliJ with VM options of Run/Debug configurations.
and in maven, I think maybe need other option to set for compile code but this is not and it's like other projects

Was this page helpful?
0 / 5 - 0 ratings

Related issues

devxpy picture devxpy  ยท  5Comments

mbj2007 picture mbj2007  ยท  4Comments

Losses picture Losses  ยท  3Comments

joshchernoff picture joshchernoff  ยท  5Comments

RadRussianRus picture RadRussianRus  ยท  3Comments