简体   繁体   中英

Can't find property files on classpath

I'm trying to load/read property files on glassfish 3.1 server. I can't get it to work. I've searched and tried many possible solutions. None worked so far, always NULL as result.

I've tried methods from the following link: How to use a property with Glassfish

My method:

final public class GTS_Properties{

...

   public static Properties getPropertiesFromFile(String fileName){
      URL url = GTS_Properties.class.getResource(fileName)
      ...
      // url is always null
   }
}

My configuration: Folder properties on build path.

/root/WEB-INF/classes/****.properties

How the Glassfish server looks like (using eclipse startup plugin)

/glassfish-root/domain/eclipseApps/MyWebApp/WEB-INF/classes/****.properties

I have tried to put the property files directly in WEB-INF instead of classes. same result.

I solved it by first going 2 'parent folders up' from the startpoint of the relative path. Inserting "../../" on the start of the path was all that was needed.

WEB-INF/classes/WebApp/utils/GTS_Properties.class (The class to get the resource from) WEB-INF/classes/prop.properties (Location of the resource file)

GTS_Properties.class.getResource("../../prop.properties")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM