Just double checking… are you using JMP (the JME IDE) or some other development environment?
The part that automatically packages up the assets directory into an assets.jar file is part of the JMP ANT build scripts… and it should “just work” in that case. Assuming the file names are identical including upper and lower case, that is.
pspeed said:
Just double checking... are you using JMP (the JME IDE) or some other development environment?
The part that automatically packages up the assets directory into an assets.jar file is part of the JMP ANT build scripts... and it should "just work" in that case. Assuming the file names are identical including upper and lower case, that is.
Did you refresh your ws, do you have build automatically turned on and is the texture located in your workspace root(check if in the bin folder after refresh). The default asset manager uses the classpath locator. So it must be in a loc. for your classloader.
The assets are normally loaded from the class path while the project is mostly executed from the project directory, hence the differences in deployment / running from the IDE. So you probably import the jme3-testdata.jar to the class path (which is why you can load the example models) and don’t do anything about the assets folder. Hence the application cannot access the data. What jMP does is it adds the assets folder to the run class path of the project and on deployment it creates a jar file from the folder which is added to the class path. If thats too much to understand its probably best to create the project using jMP even if you want to use Eclipse for coding because “you know it better”
I don’t know how to do this in Eclipse as I just took the easy route.
In general, the assets have to be in an assets.jar and the assets.jar has to be on the classpath. (Actually, the jar can be anything as long as its on the classpath.) As I understand it, by default the AssetManager will look in the classpath, ie: load class resources. You can register other locators if you want different behavior.
so i still can’t understand why if I add the assets folder to the classpath (or add it as assets.jar) I cannot get the resource located?
Normen, I dont wanna switch to JMP just to locate one resource, that simply does not seem logical. How can I explicitly put that obj file in the project to be read in other IDEs such as Eclipse? If i understood u correctly, I did add the assets folder to the run class path of the project and also created a jar file (called assets.jar) from the folder which is added to the class path as well. That still doesn’t do it.
Well when you create an Android or any other project with eclipse then that project is also created by some external tool and eclipse just shows you the content of the files etc. A jMP generated project makes sure you get all the benefits of the deployment options and extensions for the SDK, so you are sure to have a “standard” jME3 project that people can easily help you with. Eclipse can handle ant-based projects fine normally.
As for the paths, theres no other magic going on, just make sure your IDE and/or distribution jar knows its class path and that you use correct case… Also if you add the “assets” folder to the class path then you don’t need to prefix the path with “assets” obviously.
URL u = SomeClass.class.getResource( “/com/jme3/math/Vector3f.class” );
System.out.println( “Test1:” + u );
u = SomeClass.class.getResource( “Textures/OneOfYourTextures.jpg” );
System.out.println( “Test2:” + u );
[/java]
Filling in SomeClass and “OneOfYourTextures” as appropriate. Note: make sure to not include the “assets” part unless you also strangely put that in your jar for some reason.
garnaout said:
[java]URL u = Jme3Cinematics.class.getResource( "/com/jme3/math/Vector3f.class" );
System.out.println( "Test1:" + u );
u = Jme3Cinematics.class.getResource( "Models/spatial.obj" );
System.out.println( "Test2:" + u );[/java]
Test1:jar:file:/C:/Users/garnaout/Desktop/My%20Work%2032/jME3_08-04-2011/jMonkeyEngine3.jar!/com/jme3/math/Vector3f.class
Test2:null
Yes, as Normen points out, this test illustrates one absolutely irrevocable and irrefutable fact: Models/spatial.obj is not on the classpath in any conceivable way that Java knows about. Figure that out and the asset manager will be able to find your asset.
garnaout said:
[java]URL u = Jme3Cinematics.class.getResource( "/com/jme3/math/Vector3f.class" );
System.out.println( "Test1:" + u );
u = Jme3Cinematics.class.getResource( "Models/spatial.obj" );
System.out.println( "Test2:" + u );[/java]
Test1:jar:file:/C:/Users/garnaout/Desktop/My%20Work%2032/jME3_08-04-2011/jMonkeyEngine3.jar!/com/jme3/math/Vector3f.class
Test2:null
snipped potentially incorrect random ranting. ;)
Important edit I just noticed: The getResource() line for the model needs to have a "/" in front of it. So that could be causing the miss in this case... though it should not cause a problem with AssetManager. It took my clearly stating the "as quoted in the above getResource()" line to make me look at it again. :P