discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.34k stars 735 forks source link

UnsatisfiedLinkError on startup #30

Closed AjaxGb closed 8 years ago

AjaxGb commented 8 years ago

I'm working on a small, silly project in Eclipse on Windows 8.1, 64-bit. I've been using JDK 1.8.0_20 and JDA 1.2.2_139. My project is working fine in Eclipse, but when I try to pack and run it as a jar, I keep getting the same response:

Connecting to Discord...
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\toders\AppDa
ta\Local\Temp\opus360617407824081820.dll: The process cannot access the file bec
ause it is being used by another process
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.load0(Unknown Source)
        at java.lang.System.load(Unknown Source)
        at net.dv8tion.jda.utils.NativeUtils.loadLibraryFromJar(NativeUtils.java
:121)
        at net.dv8tion.jda.managers.AudioManager.<clinit>(AudioManager.java:311)

        at net.dv8tion.jda.entities.impl.JDAImpl.<init>(JDAImpl.java:62)
        at net.dv8tion.jda.JDABuilder.buildAsync(JDABuilder.java:235)
        at JohnCenaBot.<init>(JohnCenaBot.java:42)
        at JohnCenaBot.main(JohnCenaBot.java:33)

(The exact numbers after opus vary)

I am relatively new to creating jar files, so it's possible that I'm making a mistake, but I've tried this every way I can find and it still doesn't work. Using a Gradle command to pack all dependencies, referencing the library in the jar's manifest, using Eclipse to pack all referenced libraries. Once or twice it's run perfectly, but the next time it crashes again, with no changes to the files or commands. I started out with Gradle, but after a while I tried making a new, non-Gradle project and just linking to the "Dependencies Included" JDA jar. This does not appear to have had any effect on the outcome. Attached is my non-Gradle Eclipse project; it's really just one class and a sound file.

Edit by Kantenkugel: Removed token-file from zip-file JohnCenaBot_noToken.zip

AjaxGb commented 8 years ago

Jeez, thanks @kantenkugel. My bad.

kantenkugel commented 8 years ago

Here are a few things that are worth trying:

Please let us know, if you could find out anything new with the given suggestions. I am also interested in how exactly you are including JDA into your project. gradle/maven, download from build-server or adding the JDA source?

kantenkugel commented 8 years ago

By the way: i wish you luck with receiving audio... we didn't test that at all yet (yes, there are packets incoming, but we didn't check if it is easy to use or to play back). Receiving audio is not even really alpha. We are still working on finalizing the sending part (for 1.3.0 release)

kantenkugel commented 8 years ago

And... oh wow... i didn't know that we are polluting the temp-folder with all those opus.dll files

AjaxGb commented 8 years ago

@kantenkugel

I've tried the first two of those methods. Haven't tried compiling from source.

kantenkugel commented 8 years ago

No, you should not compile from source :) I was just asking to know if you did, cuz that could be a cause of error. I am really confused, on why this happens... Each instance of JDA should create its own dll-file in the temp-folder to load as library. The docs of the used methods tell us that that file is unique... and we only access it once to load it.

So somehow JDA locks itself out from the created temp-file (the code closes the output-stream to the file, but maybe it's not free again)... It is either that (we are still using it somehow before the read-attempt), or the .jar-file somehow loses permissions for the file. We will have to test this problem a little bit. This did not occur for anyone else yet, so it's gonna be hard to figure out.

If you find out anything new before we do, please let us know. Also feel free to join our channel in the Discord API Guild (invite in README-file), to have a better chat

DV8FromTheWorld commented 8 years ago

@AjaxGb JDA v1.3.0 has been released. Please try it and see if this problem still exists. https://github.com/DV8FromTheWorld/JDA/releases/tag/v1.3.0

AjaxGb commented 8 years ago

Yeah, it's working now! Thanks!