Do I HAVE to put the libs in the system folder?

Okay, I really don’t want to put the binaries in the system folder, it will make it too complicated for people to understand :stuck_out_tongue:

I don’t want to make a batch file to set the library path either :frowning:

well, is there a way to just load it from say, System.getProperty(“user.dir”) + “/jinput”?

I currently got this code but keeps giving me an UnsatisfiedLinkError.


public class ControllerTest {
	public static void main(String args[]) {
		System.setProperty("java.library.path", System.getProperty("user.dir") + System.getProperty("file.separator") + "bin");
		System.loadLibrary("jinput-dx8.dll");
		System.loadLibrary("jinput-raw.dll");
		Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
		for(int i = 0; i < ca.length; i++) {
			System.out.println("Found input device: " + ca[i].getName());
		}
	}
}

Error:


init:
deps-jar:
compile-single:
run-single:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jinput-dx8.dll in java.library.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
        at java.lang.Runtime.loadLibrary0(Runtime.java:823)
        at java.lang.System.loadLibrary(System.java:1030)
        at renoria.handler.ControllerTest.main(ControllerTest.java:24)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Solution please? thanks in advance.

java.library.path is a read only property which must be known on JVM boot. You will have to set it as command line flag: -Djava.library.path="…"
HTH

Hi

You don’t need to load the libs yourself. The JInput classes load the libs when the classloader creates the class objects, not an instance, so the trick is to set the properties before the class loader gets to them. The most reliable way I have found to do this is through reflection.

Create a launcher class. Do not import anything that might touch the jinput classes, except for some logging you might be able to get away with importing nothing at all. In the loader class, set the library path then look up your main class and then call it’s main method or how ever you wish you launch it. As long as the library path is set before the class loader looks for an of the jinput classes, it should work fine.

HTH

Endolf

can I have an example on how to use it with Reflection?

do you do like


Main.class.getMethod("main").invoke(args);

or what? Please give me an example 8)


public class ControllerLoader {
	public static void main(String[] args) {
		try {
			System.setProperty("java.library.path", System.getProperty("user.dir") + System.getProperty("file.separator") + "bin");
			System.load(System.getProperty("user.dir") + File.separator + "jinput-dx8.dll");
			System.load(System.getProperty("user.dir") + File.separator + "jinput-raw.dll");
			final Method appmain = ControllerTest.class.getMethod("main", new Class[]{String[].class});
			final String[] argz = new String[0];
			System.arraycopy(args, 0, argz, 0, argz.length);

			appmain.invoke(null, new Object[]{argz});
		} catch (IllegalAccessException ex) {
			Logger.getLogger(ControllerLoader.class.getName()).log(Level.SEVERE, null, ex);
		} catch (IllegalArgumentException ex) {
			Logger.getLogger(ControllerLoader.class.getName()).log(Level.SEVERE, null, ex);
		} catch (InvocationTargetException ex) {
			Logger.getLogger(ControllerLoader.class.getName()).log(Level.SEVERE, null, ex);
		} catch (NoSuchMethodException ex) {
			Logger.getLogger(ControllerLoader.class.getName()).log(Level.SEVERE, null, ex);
		} catch (SecurityException ex) {
			Logger.getLogger(ControllerLoader.class.getName()).log(Level.SEVERE, null, ex);
		}
	}
}

Wow thanks so much the above code worked!!

Hi

That code is specific to windows environment, you can try dropping the System.load calls and the jinput classes should find the native libs.

HTH

Endolf

I am surprised this really makes a difference. If at all, I would have thought you have to load the class via Class.forName(“foo.bar.ControllerTest”)…

@Offtopic
why does everyone use foo and bar?

@Ontopic

Thing.class works as well afaik

I would have expected that the classloader already has loaded “Thing” in the same way like when referencing the main()-method (since it is static), if you use Thing.class. So I don’t see a reason why calling it via reflection makes a difference to calling it directly regarding the “java.library.path” property.

Hi

I can’t find the relevant doc right now, but the JVM can (must?) do lazy class loading, but I don’t know how that varies between implementations. The safest bet is to use class.forname like cylab suggests. On the other hand, I didn’t do that in the applet loader tests and it seems to work ok there too.

HTH

Endolf

Okay I’ll switch to forName just incase other people might have a problem