Loading native without being in jme3 context

Hey guys,



i have a bit of a problem once again. First i have to say that loading the natives dynamically without declaring the library path is a good idea. But it does not work if i’m not directly in the jme3 context or better jme3 is not directly referenced. I have 3 projects. The first one contains the main. In addition i have built a jme3 viewers framework which will be used from each project which implements a special 3d viewer for different things and uses the base projects. That was mainly done to remove cyclical dependencies. The main problem is that the viewer projects are referencing jme3 and the jme3 framework. To use the viewer projects i instantiate the viewers depending on a extensions.xml-file. This file contains the class which has to be instantiated to build and use the viewer. The base project can now do something like Class.forname(…).newInstance().







For this constellation jme3 can never locate the natives. I’ve tried to reference the natives-jar from the base project. In the moment i extracted the natives and put them into the base project. That works but isn’t a good solution. Any ideas for a better one?



Regards

Moe

Yeah, thats the problem when its a closed classloader environment, same accounts for jMP and OSGI for example. I want to add classloader functionality (also to load for example binary/text files from the jME3 classpath in such a situation) to the jME3 System, maybe we can add a setter to supply a Classloader or something for loading the natives.

Wow, that was fast :wink:



Applying the classloader would be fine. Simply post it if there is such a method.



Thanks

Moe

Hi,



are there any news about setting the classloader to load the natives? Would be great if there would be a functionality like that.



Moe

No

Wouldn’t one way be to just include the natives in the jME3 jar? I don’t see why we should add this functionality just to go around this problem.

Because theres more binary files to jME3 than just the natives. For example I have to create a copy of all j3md files for the material editor to be able to read them.

Well, is there a workaround to load the natives with the constellation described above? In the moment i’ve extracted the natives jar and added the content into the lib folder of our base project. That was the only chance to get it to work.



In addition i had to register locaters and loaders manually:



[java]private void registerLoaders() {

log.info(“Registering city loaders and locators”);

assetManager.registerLoader(J3MLoader.class.getName(), “j3md”, “j3m”);

assetManager.registerLoader(AWTLoader.class.getName(), “jpg”, “png”);

assetManager.registerLoader(BitmapFontLoader.class.getName(), “fnt”);

assetManager.registerLoader(GLSLLoader.class.getName(), “glsllib”, “vert”, “frag”);

assetManager.registerLoader(DDSLoader.class.getName(), “dds”);

ClassLoader loader = getClass().getClassLoader();

assetManager.registerLocator(loader.getResource(“res”).getFile(), FileLocator.class.getName());

// TODO find a better solution (could use classpath directly)

try {

log.info(“Loading JME3 core data”);

assetManager.registerLocator("…/jme3/src/core-data", FileLocator.class.getName());

} catch (final NullPointerException e) {

log.severe(“Unable to locate jme3 core data. Add project to workspace.”);

}

}[/java]

Good ol’ classloader hacking xD

Yeah it is and i’ll have a drink if i can remove this method :stuck_out_tongue:

http://code.google.com/p/jmonkeyengine/source/detail?r=6908

Cheers!

Edit: Well, only part one actually ^^