cancel
Showing results for 
Search instead for 
Did you mean: 

access to a properties file under shared folder from a java class

wajdi_ghribi
Champ in-the-making
Champ in-the-making
I want to know how to access to a properties file that is under shared folder from a java class which will be exported later as a jar file under alfresco/lib, Thanks
2 REPLIES 2

lementree
Champ on-the-rise
Champ on-the-rise
Hi,

you need to define the properties file in a bean and use the properties in java thorugh bean property setting.

<strong>bean definition in Context file</strong>

<bean id="custom-properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">      <property name="ignoreUnresolvablePlaceholders">         <value>true</value>      </property>      <property name="locations">         <list>            <value>classpath:alfresco/extension/custom.properties</value>         </list>      </property>   </bean>    <bean id="customDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">        <property name="driverClassName">            <value>${custom.db.driver}</value>        </property>        <property name="url">            <value>${custom.db.url}</value>        </property>        <property name="username">            <value>${custom.db.username}</value>        </property>        <property name="password">            <value>${custom.db.password}</value>        </property>    </bean>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

<strong>custom.properties file</strong>

custom.db.username=alfrescocustom.db.password=alfrescocustom.db.driver=org.gjt.mm.mysql.Drivercustom.db.url=jdbc:mysql://192.168.1.118:3306/alfresco401‍‍‍‍‍‍

yogeshpj
Star Contributor
Star Contributor
You can user java's default resource bundle.
Put your properties files under shared/classes/alfresco/messages folder and you can access easily it in java class .Please refer the following snippet.

public static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("alfresco.messages.samplePropertyFile");
public static final String SAMPLE_PROPERTY = RESOURCE_BUNDLE.getString("samplePropertyName");