4 Replies Latest reply: Oct 25, 2007 1:58 AM by 807603 RSS

    how to know the path of file.

    807603
      i am facing a problem,i have prepared a jar file of an application, which should have a path-file in it & that path-file contains loaction from where applicatioin starts, and creates some file there. but i dont know loaction when i prepared the jar file.how to solve this problem.
        • 1. Re: how to know the path of file.
          791266
          Use relative paths.
          • 2. Re: how to know the path of file.
            807603
            I have to deliver a jar file which contains my classes. This jar file will be used by a vendor to code a Servlet which will access the classes in the jar file.
            One of the classes in this jar file is required to simulate a file-system (we call it "Repository"). Essentially, it creates a certain directory and reads-writes files into it.
            My problem is how to specify the path (i.e. directory location) of the "Repository". Following are the possibilities I could see :
            1. Hardcode the path in the java code - This is not desirable since we do not know it while I am preparing my jar-file.
            2. Create a properties file, put Repository.path=... as an entry and package it with the jar-file - The problem is that sine this properties file is packaged in the jar, it is read-only. Hence, it cannot be changed at runtime.

            I want to know what are the general approaches to this? Thanks in advance.
            • 3. Re: how to know the path of file.
              807603
              I recently dealt with the same problem with servlets, my solution was to feed the servlet an init param of the directory, and used method from servletContext getRealPath("/whatever/somewhere/file.txt) method to find the directory outside of the servlet context and it worked for me

              hope that helps
              • 4. Re: how to know the path of file.
                807603
                but it is not in my hand, My jar file will be used by a vendor to code a Servlet which will access the classes in the jar file. it cannot be solved by My jar file.

                My Question was

                I have to deliver a jar file which contains my classes. This jar file will be used by a vendor to code a Servlet which will access the classes in the jar file.
                One of the classes in this jar file is required to simulate a file-system (we call it "Repository"). Essentially, it creates a certain directory and reads-writes files into it.
                My problem is how to specify the path (i.e. directory location) of the "Repository". Following are the possibilities I could see :
                1. Hardcode the path in the java code - This is not desirable since we do not know it while I am preparing my jar-file.
                2. Create a properties file, put Repository.path=... as an entry and package it with the jar-file - The problem is that sine this properties file is packaged in the jar, it is read-only. Hence, it cannot be changed at runtime.

                I want to know what are the general approaches to this?