Deployment

Hello .

I am at the final stage of my game , and after deployment , i don’t see any models .

I read all the threads about deployment , and i think that the main problem could be that i am reading model information (name , where it should be moved and other) in the text file .

[java]fstream = new FileInputStream(“src/movableobjects.dat”);

dataRead = new DataInputStream(fstream);

bufRead = new BufferedReader(new InputStreamReader(dataRead));

[/java]

src directory is in each project root .

Read from the classpath and not from a file. Or make a proper AssetLoader.

could you give a little hint how to read from classpath ? . Thank you.

Sure, heres a link.

One of the best hint i have ever seen :slight_smile: .

Well i changed those 3 lines into 1 line :

[java]

BufferedReader bufRead = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("src/staticObjects.dat")));

[/java]

Now , after deploying screen crash instantly .

could you give me another hint ? :slight_smile:

i think i am messing with that directory .

src/foo probably does not end up as being under “src” in the classpath… but I don’t know how you’ve set your build up. Maybe it is still under just plain “src” and so the build ignores it.



You are basically asking for “src/movableobjects.dat” relative to the location of that .class file.



You’d be much happier treating this like an asset and putting it in the asset folder somewhere. Then looking up the class resource becomes much more straight forward even if you don’t want to go with an AssetLoader.

If its in “src” its most probably getResourceAsStream(“staticObjects.dat”); yeah. You can also put it in your assets folder if you don’t want it in your sources. It will be added to the classpath as well and from the name of the file I take it that it fits better to the assets it describes anyway…?

@normen said:
If its in "src" its most probably getResourceAsStream("staticObjects.dat");


Does the SDK automatically copy the stuff in "src" or just in "src/java", etc.? I don't remember.
@pspeed said:
Does the SDK automatically copy the stuff in "src" or just in "src/java", etc.? I don't remember.

(root)/src/ is the only source directory in a default project.
@normen said:
(root)/src/ is the only source directory in a default project.


Ah, I always forget that... I always setup my projects a little bit manually for this reason but I forgot why I do it. :)

Now it looks like :

[java]

FileInputStream fstream = new FileInputStream("assets/Interface/staticObjects.dat");

DataInputStream dataRead = new DataInputStream(fstream);

BufferedReader bufRead = new BufferedReader(new InputStreamReader(dataRead));

[/java]

While running with SDK it is okay , but after deployment , all models vanishes .

:confused:

You still have to look it up as a class resource because the src directory and raw assets directory do not exist in the deployment. You might as well have put your files in some completely different directory.



As it turns out, both approaches will work if you use the right path. With your old way:

getClass().getResourceAsStream("/staticObjects.dat" )



With the new way:

getClass().getResourceAsStream("/Interface/staticObjects.dat" )



Note the leading slash that tells it to look in the root instead of relative to the .class file.



You could also probably get away with getClass().getClassLoader().getResourceAsStream(“Interface/staticObjects.dat” )



…without the leading slash.

@egidijussadauskas said:
While running with SDK it is okay , but after deployment , all models vanishes .
:/

Probably because you didn't convert them to j3o. Please read the manual about deployment.
@normen said:
Probably because you didn't convert them to j3o. Please read the manual about deployment.


No, we are still on the class resource problem. Basic Java stuff and not j3o specific.
@normen said:
Probably because you didn't convert them to j3o. Please read the manual about deployment.

All my models are j3o.

Or maybe I misunderstood. To OP, please be more specific about “models vanish”.



I thought we were still working on the .dat file problem.

@egidijussadauskas said:
All my models are j3o.

Then they also get packed in the assets file and are available there. If you use Files to access them again, thats wrong.

None of the code I’ve seen so far will load the .dat file properly… so I’m going to assume that the j3o discussion is an unnecessary side-track for the moment.

Okay . the staticObjects file contains some information about models (first line - name , second - scale , third - location)

BoxRadiation (this is first line)

Then im appending .j3o suffix

[java]

newModel = assetManager.loadModel("Models/Final/"+objMas[0]+".j3o"); // objMAS[0] IS String with value BoxRadiation

[/java]

Can you show me the code that loads the .dat file? Nothing shown so far except my example code will actually do it.