2 Replies Latest reply on Aug 20, 2009 5:41 AM by sepp deinhofer

    reading a file stored outside the .war

    sepp deinhofer Newbie


      we are developing a servlet here that will read the content of a couple of files and outputs binary data.
      rather than storing our base-files in a database (which would be quite slow, given the size of our files) or putting them in the .war (which would prevent us from later adding files short of rebuilding/redeploying) we want to store them in a local folder of the system where our jboss-instance runs and open them as files via FileInputStream:

      o) where would be the "proper" directory to store those files?
      o) is there a "proper way" to do this (obvious extensions will be a file-upload/management servlet as a next step)?

      thanks for any help that can point us into the right direction!

        • 1. Re: reading a file stored outside the .war
          Francesco Marchioni Apprentice

          You have a few solution which are not JBoss specific, like looking for the file in the filesystem

           url = new File(fileName).toURL();
           is = url.openStream();
           return is;
           catch (MalformedURLException ignore)
           catch (IOException ignore)

          or in the current classpath:

          url =
           if (url != null)
           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 :

          Hope it helps

          • 2. Re: reading a file stored outside the .war
            sepp deinhofer Newbie

            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):


             <mbean code="org.jboss.varia.property.SystemPropertiesService"
             <attribute name="Properties">

            and in the servlet:

            String path = System.getProperty("AssetPath");
            URL url = new URL(path);
            InputStream is = url.openStream();