Hi,
When I add following line to my code:
java.net.URL url =
this.getClass().getClassLoader().getResource("MyFolder/MyPropFile.txt");
BufferedReader in = new BufferedReader(new FileReader(url.getPath()));
I am able to read file, this reaffirms your previous post about resources
directory being in CLASSPATH.
I do not understand why the code above succeeds and the one below fails
BufferedReader in = new BufferedReader(new
FileReader("./MyFolder/MyPropFile.txt"));
Thanks for you help!
While trying to sort this problem, I have bumped into another problem. In
this Bean I am using an XSLT, which in turn uses an XML file. I use standard
document function to read XML file from XSLT, for example
document('./MyFolder/MyXML.xml')/SomeXPath
When I give relative URL (as above), I get the folllowing error:
FODC0005: java.io.FileNotFoundException:
D:\installation\apache-servicemix-3.2.2\MyFolder\MyXML.xml (The system
cannot find the path specified)
Clearly the path is relative to SERVICEMIX_HOME,
How do I make this path relative to resources folder.
Regards,
Harshit
Ashwin Karpe wrote:
>
> Hi,
>
> Are you using Maven to build your artifacts?
>
> If so, then all you need to do is copy your Service Assembly Jar into the
> hotdeploy directory and start the servicemix server.
>
> The resources directory is automatically added to the classpath when a
> Maven based artifact is deployed in Servicemix. The whole point of using
> Maven is to avoid messing with the classpath variable. The directories
> that are added are the Servicemix lib directory and the
> artifact/src/main/resources directory
>
> Are you sure the deployment went without any errors? Also did you deploy
> the associated component jars in the Servicemix container. I am not able
> to clearly diagnose why this is happening since it is pretty basic and
> standard behavior in Servicemix.
>
> Just for kicks can you add the folder to the <SMX_install_dir>/lib
> directory and see what happens... This directory should also be on your
> classpath.
>
> Cheers,
>
> Ashwin...
>
>
> [email protected] wrote:
>>
>> Hi,
>> I used following code in MyBean to print CLASSPATH when the bean service
>> unit receiver request:
>>
>> String classpathValue = System.getProperty("java.class.path");
>> System.out.println("CLASSPATH" + classpathValue);
>>
>> It seems that only the following is being added to already existing
>> CLASSPATH
>>
>> ;D:\installation\apache-servicemix-3.2.2\bin\..\conf;D:\installation\apache-servicemix-3.2.2\bin\..\lib\classworlds-1.0.1.jar
>>
>> What do I do to add resources to classpath ??
>>
>> Thanks,
>> Harshit
>>
>>
>> Ashwin Karpe wrote:
>>>
>>> Hi,
>>>
>>> My sense is that the maven build did not succeed in placing an artifact
>>> into the Maven repository. My original answer below is correct and the
>>> resources directory is on the classpath since it is used in order to
>>> deploy the artifact into the servicemix server.
>>>
>>> BTW, did you verify that the SA does contain the SU and the artifact in
>>> the folder structure, I mentioned below. This could be easily verified
>>> by looking in the SA jar file.
>>>
>>> The correct path is with respect to the resources diectory and should be
>>> "./MyPropFolder/MyPropFile.txt". Please check your deployment artifact
>>> to see if the file has been placed in the deployable jar.
>>>
>>> Cheers,
>>>
>>> Ashwin...
>>>
>>>
>>> [email protected] wrote:
>>>>
>>>> Thanks for response!
>>>> I have tried each of the following, 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"
>>>>
>>>> Please Help!
>>>>
>>>> Regards,
>>>> Harshit
>>>>
>>>
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/Reading-file-with-relative-URL-from-Bean-tp21560027p21598339.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.