Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error to run tdlib in springboot project in windows 10 #3009

Closed
jonnjonnjo opened this issue Aug 5, 2024 · 17 comments
Closed

Error to run tdlib in springboot project in windows 10 #3009

jonnjonnjo opened this issue Aug 5, 2024 · 17 comments

Comments

@jonnjonnjo
Copy link

i've a springboot and try to run
./mvnw spring-boot:run '-Dspring-boot.run.jvmArguments="-Djava.library.path=src/main/resources/native/windows/x64"'

the tdjni.dll path is in here

$Projectroot/src/main/resources/native/windows/x64/dll

When i run the first script, i got

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffd34892f58, pid=17124, tid=5200

JRE version: Java(TM) SE Runtime Environment (21.0.3+7) (build 21.0.3+7-LTS-152)
Java VM: Java HotSpot(TM) 64-Bit Server VM (21.0.3+7-LTS-152, mixed mode, emulated-client, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
Problematic frame:
C [msvcp140.dll+0x12f58]

No core dump will be written. Minidumps are not enabled by default on client versions of Windows

An error report file with more information is saved as:
D:\College\Industrial Practices\socmed-service\hs_err_pid17124.log
[4.569s][warning][os] Loading hsdis library failed

If you would like to submit a bug report, please visit:
https://bugreport.java.com/bugreport/crash.jsp
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.

and then I tried to run this code in the tdjni.dll directory
java -Djava.library.path=. org.drinkless.MainClass

but, i got

Error: Could not find or load main class .library.path=.
Caused by: java.lang.ClassNotFoundException: /library/path=/

can anyone can help me in this?

@levlam
Copy link
Contributor

levlam commented Aug 5, 2024

You need to provide the argument command-line as '-Djava.library.path=.'.

Regarding the crash see #2912 (comment).

@jonnjonnjo
Copy link
Author

just to make sure, so what I need to do is basically recreate https://tdlib.github.io/td/build.html?language=Java but with having a modifiedd CMakeLists.txt, is that correct?

@levlam
Copy link
Contributor

levlam commented Aug 5, 2024

Yes, modifying CMakeLists.txt or downgrading MSVC is supposed to help.

@jonnjonnjo
Copy link
Author

Thank you, i want to make sure again. so , what i need to do is basically convert it into a .jar, add it to maven, and then then include the java.library.path in the command again ( referencing to where the .dll file are) into the arguments when running the springboot using ./mvnw spring-boot:run ?

@levlam
Copy link
Contributor

levlam commented Aug 5, 2024

Yes, after rebuilding you can pack the library in a .JAR file and use it in your project.

@jonnjonnjo
Copy link
Author

hello sir, could you help me again? just to really make sure again. so, i've to follow this instructions https://tdlib.github.io/td/build.html?language=Java, but changed the cmakelist just right after the first line, and then after that continue the installation.

after all the instruction is done, then i've to create jar using this command in the td root directory
jar cf tdlib.jar td

and after that, i've to include the jar into the pom. i also have to include the .dll using argument java.library.path when running the springboot using ./mvnw spring-boot:run, is that correct?

@levlam
Copy link
Contributor

levlam commented Aug 6, 2024

The first paragraph is correct.

I can't confirm exact steps for including the library in a springboot project.

@jonnjonnjo
Copy link
Author

i want to make sure again. everytime that i want to run the project with tdlib.jar being used inside of the java project, i must supply the java.library.path for the tdjni.dll in the script argument?

@levlam
Copy link
Contributor

levlam commented Aug 6, 2024

Yes. You can use only Java classes directly from .jar, so you need to ship tdjni.dll and its dependent libraries separately and provide java.library.path to be able to load them.

@jonnjonnjo
Copy link
Author

i'm kinda a little confused. after following the instructions in here https://tdlib.github.io/td/build.html?language=Java , do i've to follow the other instructions in here https://github.com/tdlib/td/tree/master/example/java ? like both of this
cd <path to TDLib sources> mkdir jnibuild cd jnibuild cmake -DCMAKE_BUILD_TYPE=Release -DTD_ENABLE_JNI=ON -DCMAKE_INSTALL_PREFIX:PATH=../example/java/td .. cmake --build . --target install

cd <path to TDLib sources> mkdir jnibuild cd jnibuild cmake -DCMAKE_BUILD_TYPE=Release -DTD_ENABLE_JNI=ON -DCMAKE_INSTALL_PREFIX:PATH=../example/java/td .. cmake --build . --target install

@levlam
Copy link
Contributor

levlam commented Aug 8, 2024

https://github.com/tdlib/td/tree/master/example/java contains generic description of the build process and https://tdlib.github.io/td/build.html?language=Java shows specific instructions for the chosen operating system. It is simpler to use https://tdlib.github.io/td/build.html?language=Java in most cases.

@jonnjonnjo
Copy link
Author

okay, thanks for answering. I think there are several unknown problem to me that I didn't know before ( like somehow the dlls is being imported twice or more in the runtime ).

@nguyenkatd
Copy link

Hi @jonnjonnjo , did you import tdlib to a spring boot project successful ? can you give me some tips

@jonnjonnjo
Copy link
Author

jonnjonnjo commented Aug 15, 2024

Yes, I do!

I think i got several errors.

  1. make sure you follow the instructions and change the CMake just like what levlam asked. I literally just copied the whole instructions from https://tdlib.github.io/td/build.html?language=Java and from my experience, because I executed the whole sequence , i got error because sometimes my connection appeared to failed to clone the git and then my powershell proceed into executing the next task.

  2. Make sure that there's no error in powershell when executing the job ( I got error because i don't have some libraries such as ssh, zlib, or something that i've to download independently )

  3. from that on, you could go to td\tdlib\bin and then create the jar ( I kinda forgot whether to create .jar from directory td\tdlib\bin or td\tdlib\bin\org or td\tdlib\bin\org\drinkless ), just make sure that you also check the jar using jar tf

  4. Add the tdlib dependency into your pom.xml, in my case, i created it just like this one
    <dependency> <groupId>org.drinkless</groupId> <artifactId>tdlib</artifactId> <version>1.0.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/lib/tdlib.jar</systemPath> </dependency>
    and add the tdlib.jar into src/main/resources/lib/ folder

  5. inside of your td\tdlib\bin, there's several .dll classes that's libcrypto-3-x64, libssl-3-x64, tdjni , and zlib1. copy that into
    src\main\resources\native\windows

  6. 2 out of 4 classes of that actually exist in C:\Windows\System32, i accidentally copied all of them so i "kinda" replaced the old .dll files to the C:\Windows\System32 ( i think you shouldn't follow this one )

  7. run ./mvnw spring-boot:run '-Dspring-boot.run.jvmArguments="-Djava.library.path=src/main/resources/native/windows"'. i run it from powershell

@nguyenkatd
Copy link

nguyenkatd commented Aug 15, 2024

Hi @jonnjonnjo ,

I followed the tdlib instructions and run it successful, but could not import to other spring boot project.

in the tdlib example, i added maven to it then i have installed tdlib.jar to maven local repository (mvn clean install), then import it to my spring boot project in pom:
<dependency> <groupId>org.drinkless</groupId> <artifactId>tdlib</artifactId> <version>1.0.SNAPSHOT</version> </dependency>

but when compile my spring project, it said "could not find package org.drinkless.tdlib"

@nguyenkatd
Copy link

Yes, I do!

I think i got several errors.

  1. make sure you follow the instructions and change the CMake just like what levlam asked. I literally just copied the whole instructions from https://tdlib.github.io/td/build.html?language=Java and from my experience, because I executed the whole sequence , i got error because sometimes my connection appeared to failed to clone the git and then my powershell proceed into executing the next task.
  2. Make sure that there's no error in powershell when executing the job ( I got error because i don't have some libraries such as ssh, zlib, or something that i've to download independently )
  3. from that on, you could go to td\tdlib\bin and then create the jar ( I kinda forgot whether to create .jar from directory td\tdlib\bin or td\tdlib\bin\org or td\tdlib\bin\org\drinkless ), just make sure that you also check the jar using jar tf
  4. Add the tdlib dependency into your pom.xml, in my case, i created it just like this one
    <dependency> <groupId>org.drinkless</groupId> <artifactId>tdlib</artifactId> <version>1.0.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/lib/tdlib.jar</systemPath> </dependency>
    and add the tdlib.jar into src/main/resources/lib/ folder
  5. inside of your td\tdlib\bin, there's several .dll classes that's libcrypto-3-x64, libssl-3-x64, tdjni , and zlib1. copy that into
    src\main\resources\native\windows
  6. 2 out of 4 classes of that actually exist in C:\Windows\System32, i accidentally copied all of them so i "kinda" replaced the old .dll files to the C:\Windows\System32 ( i think you shouldn't follow this one )
  7. run ./mvnw spring-boot:run '-Dspring-boot.run.jvmArguments="-Djava.library.path=src/main/resources/native/windows"'. i run it from powershell

what is the expectation should show when use jar tf tdlib.jar bro @jonnjonnjo

@nguyenkatd
Copy link

nguyenkatd commented Aug 15, 2024

@jonnjonnjo @levlam , the issue was resolved and build success when i comment out this plugins in file pom of tdlib project :):
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants