felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shamik Bandopadhyay <sham...@gmail.com>
Subject How to get absolute path of a classpath resource
Date Thu, 07 Jul 2011 23:23:40 GMT
Hi,

   I'm struggling to get the absolute file / dir path of files / directories
located under project's resource folder. The file paths are injected through
spring as :

<property name="siteConfig" value="classpath:/Test/test.xml" />
 <property name="siteDir" value="classpath:/Test/Sample" />

The directory is located under src/main/resources folder, which makes it
available as a classpath resource inside the bundle.

The property is being set as a Spring Resource object the java class. I'm
trying to access the file following way :

 File testFile = new File(this.siteConfig.getURL().getPath());

I'm passing this File object to another program which then reads it.

Here are some of the values from the two file objects :

Here's the URI of siteConfig --> bundle://249.14:1/TEST/test.xml

testFile absolute path --> C:\TEST\test.xml . As you can see, the absolute
path is just repalcing "bundle://249.14:1" with "C:\", which is incorrect.
As a result, when the program is trying to read the file, its not able to
pick it up. The absolute path shoould be
"C:\TestProject\src\main\resources\TEST\text.xml"

I'm not able to figure how to get the absolute file.

Any pointers will be appreciated.

- Thanks

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message