How to use properties file in JME

I need to use a properties file for my game in JME(in the sdk). I tried to use this snippet of code from baeldung but it didn’t work

type or paste code heString rootPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
String appConfigPath = rootPath + "app.properties";
String catalogConfigPath = rootPath + "catalog";

Properties appProps = new Properties();
appProps.load(new FileInputStream(appConfigPath));

Properties catalogProps = new Properties();
catalogProps.load(new FileInputStream(catalogConfigPath));

  
String appVersion = appProps.getProperty("version");
assertEquals("1.0", appVersion);
        
assertEquals("files", catalogProps.getProperty("c1"));re

I think I have to use assetManager but I’m unsure of how to use assetManager in this case.

1 Like

Asset manager is for cached assets. It is (by default) loading them from the classpath by prepending a “/” but otherwise is just loading class resources and then smart caching them. (It’s the asset manager’s main job to smart cache.)

For regular class resources just load the class resource:
MyClass.class.getResourceAsStream(“/my.properties”);
…or whatever.

The “Heart” add-on library includes a properties loader for JMonkeyEngine.
Here’s how you might use it:

import jme3utilities.PropertiesLoader;
//...
    public void simpleInitApp() {
        assetManager.registerLoader(PropertiesLoader.class, "properties");
//...
        Properties props = (Properties) assetManager.loadAsset(assetPath);
3 Likes