6 Replies Latest reply on Oct 25, 2007 10:42 PM by Kauê Felipe

    Application path

    Kauê Felipe Newbie

      I´m trying to save one file in my app.

      I do this:


      How can i get the real

      File arq = new File("test.txt");
      FileWriter writer;
      try {
       writer = new FileWriter(arq, true);
       PrintWriter saida = new PrintWriter(writer, true);
       saida.println(texto);
       saida.close();
       writer.close();
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      


      But this code save my file under .\rhdevstudio\jboss-eap\jboss-as\bin\test.txt

      What do i have to do to save this under my app root?
      This is the root of app:
      rhdevstudio\jboss-eap\jboss-as\server\default\deploy\FolcloreBrasileiro.ear\ (folder)

        • 1. Re: Application path
          Pete Muir Master

          Get a URL handle on a file you know the location of e.g. application.xml and construct an absolute path from that. Btw I wouldn't store files inside your ear if I were you, what happens when you deploy the ear non-exploded?

          • 2. Re: Application path
            Kauê Felipe Newbie

             

            "pete.muir@jboss.org" wrote:
            Get a URL handle on a file you know the location of e.g. application.xml

            Sorry, but how can i get this?

            "pete.muir@jboss.org" wrote:
            Btw I wouldn't store files inside your ear if I were you, what happens when you deploy the ear non-exploded?


            After situable the app this wouldn´t change it, then i think that aren´t problem in save files there. Meanwhile if i can´t save there, what do u sugest me?

            • 3. Re: Application path
              Devon Hillard Novice

              I'd go with a configured external directory myself. I agree with Pete, writing new files inside your ear isn't the way I'd go at all. Ears are really meant to be immutable deployment objects. I'd define a configurable path for the file storage like /opt/myapp/data/ or whatever makes sense to you.

              • 4. Re: Application path
                Kauê Felipe Newbie

                 

                "modoc" wrote:
                I'd go with a configured external directory myself. I agree with Pete, writing new files inside your ear isn't the way I'd go at all. Ears are really meant to be immutable deployment objects. I'd define a configurable path for the file storage like /opt/myapp/data/ or whatever makes sense to you.


                Ok. Then can i load the folder name by some propertie file? I know this in .NET framework but here i don´t! :(

                Could someone give me one example with this? Load the propertie from configuration file?

                • 5. Re: Application path
                  Norman Richards Master

                  JBoss provides server/default/data for this type of use. (or server/default/tmp for temporary files) You can lookup the data directory from the ServerConfig MBean. I think it also may be available in the jboss.server.data.dir system property.

                  • 6. Re: Application path
                    Kauê Felipe Newbie

                    I´ll try this! Thanks a lot!!!