Loading Assets (scenes & models) in a JavaFX project

Hello Everyone,

I am making a JavaFX project (making the main interface) but which also extends SimpleApplication. The idea being that I can have a JavaFX interface and also run a 3D world in a separate window.

I have JavaFX working fine and so too with the 3D view, but I cannot load any assets. (I currently have a black window of default size showing the fps, vertex count etc).

I changed the project.properties file of this project to include the lines:


…and copied/pasted the assets-impl.xml from another project across to this one.

I have also added

	<extension file="assets-impl.xml" id="assets">
            <dependency dependsOn="-init-assets" target="-do-init"/>

…to the project.xml file.

The project compiles and builds absolutely fine. When I go to type in an asset I want to load, it even finishes off what I’m typing (eg. if I type “foldername/sampleasset” it will prompt me with “.j3o”. I can also view the moodel in the model/scene viewer.

When I try to run it however, I get “com.jme3.asset.AssetNotFoundException: assets/Scenes/theScene.j3o

What might I have done wrong, please?
Is there something I’ve missed?


I have been able to work around this problem by adding the line:

assetManager.registerLocator("./assets", FileLocator.class);

…to my code. But I am still not sure why I ever needed to - this has never happened before for a project I’ve worked on.

I’ll let you know if I have any more problems


DISCLAIMER: I don’t use SDK for my javaFX+JME project, I use eclipse + gradle + JME-JFX

I guess you use SDK and create a JavaFX project from netbeans template. AssetManager is only setup for project created with JME template. It’s why you’ll have to customize lot of stuff, and I guess you don’t have access to jme project extension (like deployment feature, path completion in asset path,…).

About your workaround, it’ll not work at deploy time if asset forlder is packaged into the jar (the common behavior). IMHO a better workaround is to add asset folder as source/resources path In the IDE. (no need to register classpath is registered by default).

So you’re saying (in my case) place the Scenes folder in the project directory (the same directory as the “src” folder) and then use the asset manager to load the model as before:

Spatial scene = assetManager.loadModel("Scenes/theScene.j3o");     

…? I just tried that and it produced the same error, but I’m probably misunderstanding what you’re saying.

What I said is : add “project/assets” folder as resources folder (not as source folder, filter can be different).

If the issue is “assets/Scenes/theScene.j3o” then you can try to add project/rsrc as resources folder and move “assets” under rsrc, to have assets as a first fragment in a path in the classpath.

You didn’t add the target from assets-impl.xml to the init (?) task in the build-impl.xml

Question is why you have to do this manually anyway instead of using a normal BasicGame project…?

What David says is mostly unrelated general things about classpaths…

Hi Normen,

It’s because; if try to do this, the compiler can never seem to find the JFX libraries.

Using this setup works fine for a JavaFX project, but not for a BasicGame project.

…If I just create a JFX project and import all the JME3 libraries, it seems to work fine (other than the asset loader, as describe in the post).

I have just managed to get it working as a BasicGame project, having imported the following libraries:

It compiles and runs fine now :smile:
…No need for the:

assetManager.registerLocator("./assets", FileLocator.class);

Thanks for all your replies - I am very grateful. If you have any further suggestions, by all means let me know!

You are under jdk7 by any chance? Cause 8 does include jfxrt by default.