3 Replies Latest reply on Jul 4, 2006 1:01 AM by norman.richards

    How to access files from seam code

    shasho

      Hello

      I want to be able to access files on my server (HTTP/FTP). Currently I am using the following command to read a file

      InputStream stream = Resources.getResourceAsStream("/WEB-INF/" + fileName);


      The thing is, the WEB-INF/ is under the ear file, so each time I want to add new file I need to re build the ear?

      I want to be able to read files from the local apache (http) or FTP directory

      Thanks
      Amir


        • 1. Re: How to access files from seam code

          Maybe I don't understand the problem, but non-web resources can be retrieved from the file system via regular Java IO. See FileInputStream.

          • 2. Re: How to access files from seam code
            gavin.king

            Then I think you need to do a new File(....). getResourceAsStream() is only for loading stuff from the classpath.

            • 3. Re: How to access files from seam code

              In addition to what's been pointed out already:


              1) To solve the re-deploy problem, you can always deploy in exploded (directory) form. Then you'd always be able to add/change files freely. This only works if the files are inside of your myapp.ear/whatever.war directory, but it does solve your redeploy problem

              2) If you want to really externalize this, you might also look at the ExternalContext MBean. (section 3.5.3 of the JBoss AS Guide) You can bind any just about any file system like structure (local or remote) into JNDI and access the resources that way. It's a bit heavy of a solution, but it is very flexible.