Load DLL outside or inside JAR?

First of all: the return of endolf gives me hope, I’m hoping for some guidance :slight_smile:

I just couldnt let the old JInput version be… I like the way the Axis class work and i.e. how the game characters move based on this, so:

Been trying for 3 days to load a native library file, dxinput.dll (yes from an older JInput version), to make my game work with gamepad support.
That is, when running the app as a JAR; in NetBeans all functionality is there. I’ve totally given up on loading the dll from within the JAR (from a “lib” folder), but I even fail to load it in any way; with an absolut path, say “C:/Test/dxinput.dll” using the System.load() or System.loadLibrary().

The files I’m using are these:

jinput.jar
jutils.jar
win32-x86-directinput-plugin.jar
linux.jar
linux-eventinterface-jinput-plugin-0.1.jar
dxinput.dll
libjinput.so
libLinuxEventInterface-i386.so

Please, I NEED help with this, how do I make this work?? :-\

Thanks in advance!

/ Anders

Hi

This sounds like a Netbeans setup kind of thing, and I can’t help there as I don’t use it. Have you tried running from a dos prompt as show in the getting started thread?

Endolf

Thanks for taking the time to answer, feeling better already :slight_smile:

However, the application IS running perfectly in NetBeans with JInput and the above files; my characters move as expected when using my gamepad. The very annoying issue is regarding the deployment of the app - I want to run it as a JAR, with all files included in it. But the gamepad don’t get registered somehow; the missing link is dxinput.dll.

So, I don’t care anymore if the DLL gets loaded from within the JAR - I just need for it to get loaded at all, at any cost almost 8) Could you (or someone else ) please explain generally how you would do the following:

  1. Bundle the app’s files (.class, images, sounds etc) as a JAR. This I know how to do :slight_smile: A bit unsure though on how the manifest file should be?
  2. Get the app’s main class inside the JAR to load a native lib (dxinput.dll in my case), from outside the JAR. Would be satisfied just to create a deployment folder that includes the JAR + the native library, and distribute this folder to anyone who might be interested.

This is all I want to do, getting somewhat desperate now as I feel that this really is a trivial matter? I would be extremely happy if I could make this work, thanks for listening :slight_smile:

/ Anders

I have a solution, but you may / may not like it.

Ok, the reason everything is so difficult is because Jinput uses System.LOADLIBRARY, which is bad. Our goal is to use System.load() on a absolute path to where the dlls are.

So, get the source of jinput (newest version), and make a new class:


package <something>
public class System {
	public static void loadLibrary(String lib_name){
                    return; //We'll completely ignore all loadlibrary calls from jinput.
	}
}

Then, do a FileSearch on all of jinputs classes for “System.loadLibrary” and replace it with “.System.loadLibrary” It should replace 3-4 instances.

Then, if you export the new jinput as a jar, run your code, nothing will work, because its not loading anything.

So, we can load it ourselves now:


//Code cut out, it's not hard, just look up the System.getProperty("os.name") field on the internet
switch(ostype){
				case WINDOWS:
					System.load(runningDir+File.separator+"jinput-dx8.dll");
					System.load(runningDir+File.separator+"jinput-raw.dll");
					//System.load(runningDir+File.separator+"jinput-wintab.dll");
					break;
				case MACOSX:
					System.load(runningDir+File.separator+"libjinput-osx.jnilib");
					break;
				case LINUX: case 4231: //Solaris
					System.load(runningDir+File.separator+"libjinput-linux.so");
					break;
				}

:stuck_out_tongue: I’ve had to do this with almost every java library I"ve ever used (Jogl, Gstreamer, etc.)

Thanks for clearing things up :slight_smile:

With the risk of sounding like a complete moron now :o :

If I still would like to use the older JInput version I have in my current code (where everything runs/works great in NetBeans with gamepad), can your code above accomplish the same thing, in the case of loading dxinput.dll (the only DLL in this version)?? THAT would be excellent.

You may not have read my other recent posts, but I have got gamepad support working with an executable JAR, together with the latest JInput version. This might sound offensive to some :wink: ; what’s the problem if he’s already got it working?? Well, I really really would like to work with the old Axis class I have in my current code. It’s just a question of loading the DLL for that version…

Many thanks for your input!! I will try your code + some other workarounds I might not have tested yet.

/ Anders

For now I think I have to give up, after 4 days of struggling. I will have to work on modifying my code to suit the latest JInput instead, which for some reason d o e s work when executing my app as a JAR. So that’s a good thing of course, it’s just hard to let go when it should be SO simple…

Endolf: if you read this, I would like some help with my other post “Polling two components…”. After testing some it feels like the Event class among others, forces me to change the code quite a bit. I’m struggling to poll two components at the same time; gamepad button press + polling left/right on an analog stick for example? Surely this must be possible?

If you or anyone else has some info on this, the above mentioned thread is available :slight_smile:

Good night!

/ Anders