This content has been marked as final.
Show 2 replies
-
1. Re: reading a file stored outside the .war
f_marchioni Aug 19, 2009 5:02 PM (in response to sdein)You have a few solution which are not JBoss specific, like looking for the file in the filesystem
try { url = new File(fileName).toURL(); is = url.openStream(); return is; } catch (MalformedURLException ignore) { } catch (IOException ignore) { }
or in the current classpath:
url = Thread.currentThread().getContextClassLoader().getResource(fileName); if (url != null) { try { return url.openStream(); } catch (IOException ioe) { } }
With JBoss you have one service named "Properties MBean Service" which allows loading a property file from an available URL.
See this tip :
http://www.mastertheboss.com/en/jboss-howto/42-jboss-config/151-how-to-inject-system-properties-to-jboss-.html
Hope it helps
Francesco -
2. Re: reading a file stored outside the .war
sdein Aug 20, 2009 5:41 AM (in response to sdein)thanks!
what we did was to use the "properties mbean service" from the link together with an input stream opened via an url. this seemed like the most future-proof way of setting this up (web-service and asset-storage are completely decoupled from each other):
property-service.xml:<server> <mbean code="org.jboss.varia.property.SystemPropertiesService" name="jboss:type=Service,name=SystemProperties"> <attribute name="Properties"> AssetPath=file:///g|projects/ourProject/assets/test.txt </attribute> </mbean> </server>
and in the servlet:String path = System.getProperty("AssetPath"); URL url = new URL(path); InputStream is = url.openStream();