jme3 and OSGI


recently I have come accross some problems concerning jme3 used with OSGI framework.

I found some jme3 design features that really made my goals hard to achieve.

But let's start from the beggining  :slight_smile:

First problem

I write an application that uses jme3 and lwjgl. I downloaded jme3 (nightbuild from 10.08.2010) engine and the latest lwjgl library (version 2.5).

Because OSGI is based on the idea of bundles (each bundle is a separate jar file in the end and a separate project in eclipse during development) I decided to split my application so that each bundle can be replaced with the newest version separately.

And thus I hava a bundle named lwjgl and bundle named jMonkeyEngine. The problem is that I want to keep the native libraries in lwjgl bundle, so that I can replace the graphic engine only.

Current implementation do not allow it. The reason is simple.

I call the method:

public void start(JmeContext.Type contextType);

from Application class.
This method is trying to create JmeContext using this piece of code:

context = JmeSystem.newContext(settings, contextType);

The class JmeSystem has only static methods.
In the newContext method it calls the initilialize method and inside a method that actually loads the native libraries.

Natives.extractNativeLibs(getPlatform(), settings);

As you may see it is a static method of the Natives class. It calls the following method:

protected static void extractNativeLib(String sysName, String name) throws IOException;

and it performs the following:

String path = "native/"+sysName+"/" + fullname;
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);

And the second line is the core of my problem.
Each bundle has its own classloader and the method getResourceAsStream() loads only from the current jar file which is ... jMonkeyEngine.

In this implementation I can see no way to load the natives from lwjgl bundle.
Is there any chance to improve it so that the loading of natives could me more customizable ?

I could do with a simple interface with a method loading the inputStream which I would be able to provide from outside.

Second problem:

I wanted to have my application more customizable. For example I do not need to load all the default assets I totaly want to use my own. But the current implementation of Application class makes it hard to change that,

It loads these assets in a private method so I cannot alter it when extending this class.
This is the method:

private void initAssetManager(){
        assetManager = JmeSystem.newAssetManager();

and it creates the manager that loads the default assets. And if I wanted to use my own implementation of the asset manager I simply have to wait first for this manager to load itself along with the data.

Is there any chance to make the methods protected instead of private ?? I mean all the methods that actually initialize something in the Application class.

Third problem:

This is the last one and most trivial.
I use the MouseAxisTrigger class and it has the private parameter:

private boolean negative;

but there is no getter to it  :)
I can get it using reflection but it really complicates the code.

OK I hope that at least a couple of people made it to the end  :D
If something is unclear (and I'm almost sure it will be) ... just ask.

Best regards,

Your first problem is one that I have in jMonkeyPlatform as well. Since the natives and other things (e.g. Material definitions) are no classes theres no proper way of loading them from another plugin/bundle. I rather regard this as a limitation of osgi/nb plugins. Maybe nag Oracle?

The second problem isnt really one afaics… The default assetManager does not load any assets, its just some loaders that are registered. If you really dont want them to be included you could also just set your own assetManager like assetManager=new DesktopAssetManager(). But you're probably right that the init method should be protected.

Third thing i dont really know, what does the negative variable do that you want to access it? It will be triggered in both directions anyway i think?



about 3.

The negative attribute depend on the direction you move the mouse on the axis(i think up and left are negative)

you need to register the axis with the input manager


   inputManager.addMapping("moveMouseLeft", new MouseAxisTrigger(0, true));
   inputManager.addMapping("moveMouseRight", new MouseAxisTrigger(0, false));

in the Analog or Action listener you can keep track on the negative value just by testing the binding name
What are you trying to do exactly?

Thanks for the answers :slight_smile:

As for the first problem …

… the only solution I can think of now is my own implementation of Natives and JmeSystem.

I know it is a problem in OSGI with separate class loaders. So far I managed to use some kind of proxy classes that allowed me to perform operations that needed to be done in another bundle.

I'm not going to abandon osgi now  8) It works quite well now, except of course of these rare problems.

And btw. what is 'nag Oracle' ???

The second one …

… yes you are right, it loads only config. I was puzzled by the parameter loadDefaults and I thought that it loads the default assets  :slight_smile:

And the third one…

… I need to save my keyboard mapping configuration as well as mouse configuration. That is why I could use such a method  :wink:



Kaelthas said:

And btw. what is 'nag Oracle' ???

Lol, sry I meant you should maybe ask the creators of the osgi standard to extend it so other things than classes can be shared between plugin classpaths properly.

About #1, you could simply combine jme3 and lwjgl in one plugin, another version of the plugin would contain jme3 and jogl. You would not want to use one without the other anyway I guess?


Yeah I think I try it that way for now :slight_smile:

And if it happens that I find a proper solution I'll post it here.

Thanks a lot,