Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
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  
  [HELP]jinput and platform indipendent native loader  (Read 5684 times)
0 Members and 1 Guest are viewing this topic.
Offline lesto

Senior Newbie





« Posted 2011-10-27 01:22:36 »

hi,
I can't understand why this doesn't work:
1  
2  
3  
String jinput = System.getProperty("java.library.path")+File.pathSeparator+ new File(System.getProperty("user.dir").toString()+ File.separator+"lib" + File.separator + "dist");
        System.out.println("Loading native library from: " + jinput);
        System.setProperty("java.library.path", jinput);


it has worked for lwjgl (but instead of "java.library.path" was "org.lwjgl.librarypath")

i've take a look in the forum, and many link directly the DLL file. I don't like this approach, as it isn't platform independent, so java loose it's greatest quality.

using the -Djava.library.path with the PATH created above everything works.

please tell me how solve this.

thank you
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #1 - Posted 2011-10-27 06:52:43 »

The jinput plugins for each platform load the library as soon as they are loaded by the JVM (done in a static block). So if any of the classes you import in your main app, or any they import etc are jinput ones, the library is loaded before you change the library path.

The way I'd solve this is with reflection, my launcher class doesn't import anything directly to do with the rest of my game or jinput, it sets the library path, then gets the main program class from the string classname, then it constructs an instance of that and off it goes with the new library path.

HTH

Endolf

Offline cylab

JGO Ninja


Medals: 52



« Reply #2 - Posted 2011-10-27 08:17:36 »

http://www.java-gaming.org/topics/do-i-have-to-put-the-libs-in-the-system-folder/20162/msg/162024/view.html#msg162024
http://www.java-gaming.org/topics/exporting-java-game-using-jogl-into-only-one-jar-in-eclipse/20526/msg/166968/view.html#msg166968

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline R.D.

Senior Duke


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #3 - Posted 2011-10-27 09:08:10 »

I usally do this likt this:
1  
2  
System.setProperty("org.lwjgl.librarypath",new File(new File(System.getProperty("user.dir"), "native"), LWJGLUtil.getPlatformName()).getAbsolutePath());
System.setProperty("net.java.games.input.librarypath", System.getProperty("org.lwjgl.librarypath"));


These are the first lines in my Main and I just copy the native folder next to ma jar (or in eclipse in the project path) Shocked

You know, JInput provides it's own Property too Smiley (Not sure but maybe there is lacking documantation here Cheesy)
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #4 - Posted 2011-10-27 09:31:07 »

You know, JInput provides it's own Property too Smiley

It does indeed, but this again would need to be set before any of the JInput classes are loaded by the JVM, which means before any class is loaded that imports them or uses them. And before any classes that import or use the classes that import or use jinput etc etc. Unless you do it via reflection or some other class loader.

Endolf

Offline R.D.

Senior Duke


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #5 - Posted 2011-10-27 09:52:42 »

You just provide these to lines I posted in your main at the very beginning. So you don't need to use reflection Cheesy Or ist this another case of "How a programmer should handle things and how he does in in a real application?"
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #6 - Posted 2011-10-27 09:55:57 »

Like I said, jinput loads the libs up statically as the class is loaded, so anything that causes the classes to be loaded *before* the properties are set will cause JInput to not have the new value of the properties.

Imports or uses of the class in code will cause it to get loaded (at least on some JVMs if not all).

Endolf

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 818
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2011-10-27 13:51:36 »

So if any of the classes you import in your main app, or any they import etc are jinput ones, the library is loaded before you change the library path.
Imports or uses of the class in code will cause it to get loaded (at least on some JVMs if not all).
Imports do *not* load the class. Imports are a language level construct and do not exists in bytecode. Classes only get loaded once they are used. AFAIK the only way a class can get loaded before the first line of the main-method, is a static block in that very same class.

You can verify this by using -verbose:class

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #8 - Posted 2011-10-27 13:58:51 »

Importing was perhaps the wrong wording. If you use any class, except through reflection, the JVM seemed to load this, upfront, before any code was executed. I'm guessing it was just an optimisation that was done, preloading all the classes it knew about. The only way round this was to create a wrapper class with a main that changed the property values, and then using the thread context class loader, to load the main class of the program from it's string name. This meant that the JVM did not preload the JInput classes and did not execute their static blocks *before* the properties were set.

Endolf

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 818
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2011-10-27 14:19:34 »

I've never seen the JVM load classes upfront.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline R.D.

Senior Duke


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #10 - Posted 2011-10-27 15:28:21 »

Like I said, jinput loads the libs up statically as the class is loaded, so anything that causes the classes to be loaded *before* the properties are set will cause JInput to not have the new value of the properties.

Imports or uses of the class in code will cause it to get loaded (at least on some JVMs if not all).

Endolf

Don't get me wrong, I know what you mean but where is the problem in setting the first two lines of code in Main to the ones I posted? I want to be "loaded" anyway so why not doing this?
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #11 - Posted 2011-10-27 17:14:22 »

It's just the order that things get done. I found that the classes were getting loaded and the static methods called before the main was executed, so changing the values of properties in the main method had no effect.

Endolf

Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #12 - Posted 2011-10-27 17:20:21 »

In java 1.6.0_23 on windows it does not seem to load the classes up front like it used too. So feel free to ignore everything I've said if you are aiming at 1.6+ Smiley

Endolf

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 818
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2011-10-27 18:37:32 »

In java 1.6.0_23 on windows it does not seem to load the classes up front like it used too. So feel free to ignore everything I've said if you are aiming at 1.6+ Smiley
Which version did?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #14 - Posted 2011-10-27 18:48:12 »

What ever it was I tested a few years back, no idea which version. I don't have old jdks installed to try Smiley

Endolf

Offline lesto

Senior Newbie





« Reply #15 - Posted 2011-10-27 19:37:59 »

maybe your main class was extend (like mine) another class with global jinput's class. maye this is why static setting isn't working. Now I'm going to put the main in another class (with the static classpath set and everything). lets see if this does the trick.
BTW linux 32bit and oracle JVM 1.7

edit: haven't changed main but tested "System.setProperty("net.java.games.input.librarypath", jinput);" in static, and everything works now! thanks!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 818
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2011-10-27 19:50:17 »

http://blog.cedarsoft.com/2010/11/setting-java-library-path-programmatically/ persecutioncomplex

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #17 - Posted 2011-10-27 20:42:44 »

That could solve a lot of our pain!!!

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.

theagentd (16 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!