[opencms-dev] .properties file
Kai Widmann
Widmann at mediaworx.com
Mon Jun 30 15:20:47 CEST 2014
Hi,
sure that’s possible. Since classes are usually exported to WEB-INF/classes/… you could either get the properties file from the real file system or you could use the class loader to access the properties file.
Here’s an example for using the class loader:
public class ContentTypeConfiguration {
private static final Log LOG = LogFactory.getLog(ContentTypeConfiguration.class);
private static final String PROPSPATH = "com/mediaworx/b4f/opencms/contenttypes/ContentTypeConfig.properties";
private static final Properties prop;
static {
prop = new Properties();
try {
prop.load(ContentTypeConfiguration.class.getClassLoader().getResourceAsStream(PROPSPATH));
}
catch (IOException e) {
LOG.error(PROPSPATH + " could not be loaded.");
}
}
[...]
}
I’m sure there are other ways (e.g. ResourceBundle), but this has worked for me so far.
Cheers
Kai
Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] Im Auftrag von Dudu Zoltan
Gesendet: Montag, 30. Juni 2014 15:13
An: The OpenCms mailing list
Betreff: [opencms-dev] .properties file
Hi,
Is it possible to read a .properties file from within a module.
So, for instance, if I have a module com.myexample.mymodule with an action class MyAction.class and a mymodule.properties file, is it possible to read the .properties file from the action class?
accessing the file by name only (they are on the same path) does not work and accessing by '/system/modules/com.myexample.mymodule/classes/com/myexample/mymodule/mymodule.properties' does not work also.
thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20140630/74e7fdaf/attachment.htm>
More information about the opencms-dev
mailing list