<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Extreme Pattern: osgi.configuration.area and FileSystemResource</title>
    <link>http://blog.extremepattern.com/articles/2006/12/18/osgi-configuration-area-and-filesystemresource</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>enjoy</description>
    <item>
      <title>osgi.configuration.area and FileSystemResource</title>
      <description>&lt;h3&gt;源起&lt;/h3&gt;


	&lt;p&gt;程式都需要一些設定檔或是資料庫檔，然而這些檔案的安裝位置並不一定是絕對的，
所以執行時需要取得當時環境的資訊來調整，往往是根據安裝時放置的相對位置來決定，
像要練習如何取得 OSGi 執行時期的檔案位置，以及處理 Spring-OSGi 不支援 Resource 
注入的替代方案。&lt;/p&gt;


	&lt;h3&gt;參考&lt;/h3&gt;


	&lt;ol&gt;
	&lt;li&gt;&lt;a href="http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html"&gt;Eclipse Runtime Options&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://opensource.atlassian.com/projects/spring/browse/OSGI-45"&gt;Can&amp;#8217;t Find Resources outside of the bundle&lt;/a&gt;&lt;/li&gt;
	&lt;/ol&gt;


	&lt;h3&gt;Eclipse runtime options&lt;/h3&gt;


	&lt;p&gt;使用 Equinox osgi 執行時會提供一些環境參數
 ，程式中可以用 System.getProperty() 取得執行時期一些
檔案路徑來使用，下面為一個 bundle 在 Eclipse &lt;acronym title="windows"&gt;PDE&lt;/acronym&gt; 平台
的測試的範例。&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;osgi.configuration.area=
file:/C:/EclipseInstall/eclipse-3.2/configuration/&lt;/li&gt;
		&lt;li&gt;osgi.install.area=
file:/C:/EclipseInstall/eclipse-3.2/&lt;/li&gt;
		&lt;li&gt;osgi.instance.area=
file:/C:/myproject/Haha2007/&lt;/li&gt;
		&lt;li&gt;osgi.instance.area.default=
file:/C:/Documents and Settings/Foo/workspace/&lt;/li&gt;
	&lt;/ol&gt;


	&lt;h3&gt;File Resource&lt;/h3&gt;


	&lt;p&gt;之前使用 Spring Resource 注入的 bean，放到 OSGi 環境會出現檔案問題，根據參考連結的解法，需要自行產出 FileSystemResource 來使用。&lt;/p&gt;


&lt;pre&gt;
&amp;lt;bean 
class="org.sf.beans.factory.config.PropertyPlaceholderConfigurer" /&amp;gt;
&amp;lt;bean id="haha" class="xx.yy.zz"&amp;gt;
&amp;lt;property name="fooFile"&amp;gt;
   &amp;lt;bean class="org.sf.core.io.FileSystemResource"&amp;gt;
      &amp;lt;constructor-arg&amp;gt;${osgi.configuration.area}&amp;lt;/constructor-arg&amp;gt;
   &amp;lt;/bean&amp;gt;
&amp;lt;/property&amp;gt;
&amp;lt;/bean&amp;gt; 
&lt;/pre&gt;

	&lt;p&gt;不過 FileSystemResource 不吃 file: 開頭的字串，乾脆轉成下面做法。&lt;/p&gt;


&lt;pre&gt;
&amp;lt;bean 
  class="org.sf.beans.factory.config.PropertyPlaceholderConfigurer" /&amp;gt;
&amp;lt;bean id="haha" class="xx.yy.zz" 
  p:osgiConfArea="${osgi.configuration.area}"/&amp;gt;
&lt;/pre&gt;

	&lt;h3&gt;觀察&lt;/h3&gt;


	&lt;ol&gt;
	&lt;li&gt;osgi.configuration.area 不清楚是否 OSGi 規格有提到，如果沒有，其他執行平台不一定會支援。&lt;/li&gt;
	&lt;/ol&gt;</description>
      <pubDate>Mon, 18 Dec 2006 20:00:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:1ec1aeaa-7840-44b5-8c89-c9a5e26471cf</guid>
      <author>LIN</author>
      <link>http://blog.extremepattern.com/articles/2006/12/18/osgi-configuration-area-and-filesystemresource</link>
      <category>java</category>
    </item>
  </channel>
</rss>
