Jump to content
  • Advertisement
Sign in to follow this  
wrAthchild

[java] problem with JAR + native file (.dll) - JInput / gamepad

This topic is 3809 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I was hoping for some input on a very annoying problem of mine. Feeling is it must have a simple solution... I've developed a Java game which makes use of JInput, in order to have gamepad/joypad support. In addition to some JAR plugin files JInput also includes some native libraries (for Win/Linux support). Everythings works as expected in my IDE (NetBeans) so no problem here. However, I'm trying to bundle everything in a executable JAR (in the unlikely event that someone actually wants to try it :)). This works almost as expected; code, images and sound are all OK, but the most important piece is missing, the gamepad functionality... Both the plugins and native files are included in JAR (in "lib" folder). Im using a class loader (http://www.jdotsoft.com/JarClassLoader.php) which handles the JAR creation. The docs concerning this loader states that all files, including native ones, can be placed at any location within the JAR; the loader will find them. But somehow the gamepad functionality is not there when running the JAR hmmm. I have tried to manually set the java library path (absolute), to point at the much needed dll file (dxinput.dll), as follows: try { System.setProperty("java.library.path", "c:/MinAppFolder/MinApp/"); System.load("c:/MinAppFolder/MinApp/dxinput.dll"); // also tried System.loadLibrary("dxinput.dll") here... } catch(UnsatisfiedLinkError e) { System.out.println(e); } The above code being placed first in the program main-method. It's of course not ideal, but I did this just to test if I could get it to work at all... No luck with this option either :/ (I'm never getting UnsatisfiedLinkError though) Have any of you experienced this problem aswell? I would really appreciate some help with this, feels like I've tried all options. What am I doing wrong? / Anders [Edited by - wrAthchild on July 13, 2008 8:11:04 AM]

Share this post


Link to post
Share on other sites
Advertisement
First of all, congratulations for making a game in Java. Second, I have also had this same problem. As far as I can tell, there is no way to have the dll file in the jar file. I googled this, and found many post in forums that say the same thing. If someone knows how to do this, please let us know.

If I had to guess why this doesn't work, it is because windows can not use a *.dll in a jar file. You said you are not getting an exception when you load the library, which means that java is finding and loading the library. But that is not all that has to happen. The dll file needs to be in a folder in the PATH so windows can use the code in the dll. I have done this is the past by using the -Djava.library.path vm argument.

Share this post


Link to post
Share on other sites
I really appreciate you taking the time to answer, been frustrated and any help is welcome. I will try your PATH suggestion at once! Somehow I will get this to work, even if it kills me :)

Thanks!

Share this post


Link to post
Share on other sites
Ok, it seems like a solution has arrived :)

The best part is that the native files are actually located and loaded from within the JAR. Not been setting a single java.library.path. I have yet to work out all the details, but I successfully managed to interact with my app (executed by JAR) through a gamepad.

First of all I have been using an old version of JInput (just used the same files I found in a tutorial from 2004). That version included only one dll file, dxinput.dll. I got the latest from javagaming.org which had three dll:s, among other jars. Found out that the Axis class (of older version) was removed so I had to modify (in the process of doing this :)) some methods in my app to make it work. Great relief to see the gamepad responding at last, when running my app-jar!

Will post more info on this as soon as my app behaves like it did with the older version. In case there are more people wondering.

/ Anders

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!