Reading file with relative URL from Bean
hkapoor Jan 21, 2009 6:21 AMHi,
I have implemented a MessageExchangeListener to integrate my java class with servicemix.
I have to access a property file from this class. The class file say MyListener is in package MyPackage.
I created a folder called MyPropFolder in resources folder and inside MyPropFolder I have MyPropFile.txt
The folder structure of source is as follows
MyBean
src
main
java
MyPackage
MyListener.java
resources
MyPropFolder
MyPropFile.txt
When I create a service assembly and see inside the zip archive created the structure looks as follows:
MyBean.zip
MyPackage
MyListener.class
MyPropFolder
MyPropFile.txt
MyListener.class tries to access the property file as follows:
BufferedReader in = new BufferedReader(new FileReader("./MyPropFolder/MyPropFolder.txt"));
I get the following Exception
java.io.FileNotFoundException: ..\..\MyPropFolder\MyPropFolder.txt (The system cannot find the path specified) ...
I have tried each of the following Paths, however none of them work
"MyPropFile.txt"
"MyPropFolder/MyPropFile.txt"
"./MyPropFolder/MyPropFile.txt"
"../MyPropFolder/MyPropFile.txt"
"./MyPropFile.txt"
"./resources/MyPropFolder/MyPropFile.txt"
"../resources/MyPropFolder/MyPropFile.txt"
"../../resources/MyPropFolder/MyPropFile.txt"
Maven Build has also succeeded. When I open assembly.zip, I see appropriate serviceunit .zip in it. And when I open serviceunit.zip I see MyFolder which has MyProp.txt
Infact after deploying, when I have a look at the SERVICEMIX_HOME/data folder I see
D:\installation\apache-servicemix-3.2.2\data\smx\service-assemblies\MyAssembly\version_15\sus\servicemix-bean\MyBean\MyFolder\MyPropFile.txt
D:\installation\apache-servicemix-3.2.2\data\smx\service-assemblies\MyAssembly\version_15\sus\servicemix-bean\MyBean\MyPAckage\MyBean.class
What am I doing wrong? How do I read a file with relative URL?