Results 1 to 6 of 6

Thread: Jar file with config file

  1. #1
    Join Date
    Dec 2009
    Posts
    178

    Jar file with config file

    Hello,
    I searched a lot but did not come in contact with the reading of an external file. When I am working under eclipse and read my txt config files that are in an AC load config file config ect. When I launch the command line with my executable jar the AC does not load the config file and says can not find the config file. What is the problem here? I am confused with this concept.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Jar file with config file

    Hello,
    What I usually do when I have external files. Jar, I put them in folders next to. Jar and recover their paths, I use:
    System.getProperty("user.dir") + "/ folder / filename.ext";
    "user.dir" gives you the record of execution. jar, so if you know the config file test.properties is in the config file at the same level. jar, you can do:
    String path = System.getProperty("user.dir") + "/ config / test.properties";
    You can try this method.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Jar file with config file

    Hey,
    Note this is not entirely true: "user.dir" gives you the current directory that may very well be different from the directory of jar. To get the directory jar must use the classloader. How to find the directory containing the jar where is my class? (note this code must not walk for JWS apps). You can not tell you which must be within the file, you must know where you want to put it to define how to access.

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Jar file with config file

    Hello,
    The following considers windows as the default operating system
    String path = System.getProperty("user.dir") + "\\config\\test.properties ";
    But the best thing to define a global variable throughout the application:
    Public static String FILE_SEPARATOR = System.getProperty("file.separator");
    and finally
    String pt = System.getProperty() + + "config" + + FILE_SEPARATOR "test.properties";
    And as your code is portable (that requires java)
    Last edited by Praetor; 28-01-2010 at 02:03 PM.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Jar file with config file

    Hello,
    I had this problem (basic) as EDI. It's just that the IDE place paths during the execution, which are losing money when running in production. Here is an exmple of what I use to load the props. of Log4J, when running in production (this fragment is in the Main class, hence the "Main.class ..."
    Properties logProp =new Properties(); logProp.load(Hand.class.getClassLoader().getResourceAsStream("org/latex/report/log4j.properties"));
    Look in this direction here. It will be easier for you.

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: Jar file with config file

    Hello,
    The above show is correct, one more thing you can do is that the log4j.properties file (my case) may be in one. Jar or outside ... as long as
    org /
    is the 1st directory of the CLASSPATH. Check the information in the directories and the file and the compile the program and give us what was the result. If you get an error then you can post the error here and we will try to solve your problem.

Similar Threads

  1. Replies: 8
    Last Post: 18-04-2011, 08:09 AM
  2. Config file of Crysis 2
    By Edgar Arular in forum Video Games
    Replies: 5
    Last Post: 26-03-2011, 10:22 AM
  3. How to make changes in web.config file in asp.net
    By Meditation in forum Software Development
    Replies: 6
    Last Post: 26-02-2011, 09:56 AM
  4. Difference between Web.Config and Machine.Config File
    By Adrina_g in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 02:44 PM
  5. VB .net App.Config file in the project
    By AmolP in forum Software Development
    Replies: 3
    Last Post: 06-02-2009, 10:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,007,448.31830 seconds with 17 queries