Don, 



Assuming you are talking about a normal Java properties file (key=value on 
every line) Karaf uses something called the Configuration Admin service for 
this.  What you would do is place your properties file in the {KARAF_HOME}/etc 
directory and rename it so that it has a .cfg extension (remove any characters 
that are not included in this: [a-z, A-Z,.] from the file name also).  Then, 
you would create a spring file that looks like this: 





<beans xmlns=" http://www.springframework.org/schema/beans " 

              xmlns:xsi=" http://www.w3.org/XMLSchema-instance " 

              xmlns:ctx=" http://www.springframework.org/schema/context " 

              xmlns:osgix=" 
http://www.springframework.org/schema/osgi-compendium " 

              xmlns:osgi=" http://www.springframework.org/schema/context " 

              xsi:schemaLocation=" 

                      http://www.springframework.og/schema/beans 
http://www.springframework.og/schema/beans/spring-beans.xsd 

                      http://www.springframework.og/schema/context 
http://www.springframework.og/schema/context/spring-context.xsd 

                      http://www.springframework.og/schema/osgi-compendium 
http://www.springframework.og/schema/osgi-compendium/spring-osgi-compendium.xsd 

                      http://www.springframework.og/schema/osgi 
http://www.springframework.og/schema/osgi/psring-osgi.xsd "> 

             

            <!-- The persistent ID is the name of your properties file, minus 
the .cfg extension --> 

            <osgix:cm-properties id="myProperties" 
persistent-id="my.properties.file"/> 

            <osgi:property-placeholder properties-ref="myProperties /> 



</beans> 



Put this into a spring.xml file and place it in your   
resources/META-INF/spring  directory.  This will make all of the properties in 
that file available for injection using the same syntax as you would use with 
standard Java properties. 



I hope this helps! 





v/r, 



Karafman 


----- Original Message ----- 
From: "DonDiego761 [via Karaf]" 
<[email protected]> 
To: "karafman" <[email protected]> 
Sent: Thursday, January 6, 2011 10:54:41 AM 
Subject: My bundle using a properties file 

Hi, 

I have a problem with my bundle which is using a external properties file. 

I have the exception: 
java.io.FileNotFoundException: ServletContext resource 
[/path/to/my/file/file.properties] cannot be resolved to absolute file path - 
web application archive not expanded? 

Note that my properties file is loaded by a class created from Spring context. 

How to read a external property file? 

Regards, 






View message @ 
http://karaf.922171.n3.nabble.com/My-bundle-using-a-properties-file-tp2206312p2206312.html
 
To start a new topic under Karaf - User, email 
[email protected] 
To unsubscribe from Karaf - User, click here .

-----
Karafman
Slayer of the JEE
Pounder of the Perl Programmer

-- 
View this message in context: 
http://karaf.922171.n3.nabble.com/My-bundle-using-a-properties-file-tp2206312p2207060.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Reply via email to