Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Do I HAVE to put the libs in the system folder?  (Read 3476 times)
0 Members and 1 Guest are viewing this topic.
Offline Renoria

Junior Member




...


« Posted 2009-03-29 17:20:09 »

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

I don't want to make a batch file to set the library path either Sad

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
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.
Offline bienator

Senior Member




OutOfCoffeeException


« Reply #1 - Posted 2009-03-29 19:18:48 »

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

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #2 - Posted 2009-03-29 23:34:11 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Renoria

Junior Member




...


« Reply #3 - Posted 2009-03-30 06:18:38 »

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

do you do like

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


or what? Please give me an example  Cool
Offline Renoria

Junior Member




...


« Reply #4 - Posted 2009-03-30 06:37:43 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
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!!
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #5 - Posted 2009-03-30 08:49:48 »

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

Offline cylab

JGO Ninja


Medals: 38



« Reply #6 - Posted 2009-03-30 11:53:07 »

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")...

Mathias - I Know What [you] Did Last Summer!
Offline Renoria

Junior Member




...


« Reply #7 - Posted 2009-03-30 17:05:54 »

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
Offline cylab

JGO Ninja


Medals: 38



« Reply #8 - Posted 2009-03-30 17:44:11 »

@Offtopic
why does everyone use foo and bar?
http://en.wikipedia.org/wiki/Foo

@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.

Mathias - I Know What [you] Did Last Summer!
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #9 - Posted 2009-03-30 20:40:32 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Renoria

Junior Member




...


« Reply #10 - Posted 2009-03-31 12:49:02 »

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
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (23 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!