I have a some files which resides under below path.
path : \alfresco52\tomcat\shared\classes\alfresco\extension
I want to read that file within my java class.How Can I read?
Need more info but i give some suggestion...
if the file is some file xml configuration file for Alfresco (context,transfomer,alfresco-global-properties,ecc.),so under the path
/opt/alfresco-community/tomcat/shared/classes/
if you put in the file in the right directory Alfresco automatically load the file.
if instead they are file you want to use like resources for your java code, you can create your XML configuration context and build some Spring Bean with reference to the file.
by default the prefix "classpath:" go to look even under the "Shared" lib directory.
Example for a file in "/opt/alfresco-community/tomcat/shared/lib/er/ere/test.properties":
<bean id="ZZZZ" class="XXXXXX">
<property name="pathToFile">
<list>
<value>classpath:er.ere.test.properties</value>
</list>
</property>
</bean>
For read the properties file you can look online a piece of code java for your purpose.
File is other than resource.
It may be text file or doc file etc....
Maybe i wasn't very clear on my answer ,my bad.
You can use the spring injection with any file you want .
Usually i prefer to use a properties file (e.g. test.properties) under the "Shared" lib directory where i put some reference to the system files i need; For example a property for retrieve a pdf file: "myFile=/usr/local/src/myDocument.pdf" so i just update the value of the property without touching the java server code.
Then i inject the properties file "/opt/alfresco-community/tomcat/shared/lib/er/ere/test.properties" on my "spring-context.xml" on "/opt/alfresco-community/tomcat/shared/classes/alfresco/extension/spring-context.xml" (or you can put that even on your java project).
Then i usually use :
<bean id="properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:er/ere/test.properties</value> </list> </property> <!-- Default values for backwards compatibility --> <property name="properties"> <props> <prop key="name">value</prop> </props> </property></bean>
OR
<bean id="properties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean"
depends-on="">
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:er/ere/test.properties</value>
</list>
</property>
</bean>
Or if you just want to point to the pdf (must be under the classpath directory of alfresco) then:
<bean id="properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:er/ere/myDocument.pdf</value> </list> </property> <!-- Default values for backwards compatibility --> <property name="properties"> <props> <prop key="name">value</prop> </props> </property></bean>
at last inject the bean "properties" on your java bean class:
<bean id="ZZZZ" class="XXXXXX">
<property name="pathToFile" ref="properties
" />
</bean>
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.