aspose file tools*
The moose likes Java in General and the fly likes Unable to load properties file in Java using eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Unable to load properties file in Java using eclipse" Watch "Unable to load properties file in Java using eclipse" New topic
Author

Unable to load properties file in Java using eclipse

sarada bokka
Ranch Hand

Joined: Jan 13, 2010
Posts: 80
Hi All,

I am trying to run a standalone application which picks the robot.properties under src folder of eclipse



Eclipse throws below error where Robot is the project name .
user.dir displays -C:\Eclipse\MyProjects\Robot


Exception in thread "main" java.io.FileNotFoundException: robot.properties

Thanks in advance.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40041
    
  28
Which directory do you have that file in?
sarada bokka
Ranch Hand

Joined: Jan 13, 2010
Posts: 80
properties file is under src folder so eclipse tries to put in bin folder directly during compilation
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

First, FileInputStream is expecting a file path which has nothing to do with "user.dir". If the file path is an absolute path (e.g. /log/myfile), then it will pick up the file from that path. If the path is a relative path, like yours, it will look for a file starting from the current directory. So what it the current directory ? If you start your program from Eclipse, the current directory is by default the root directory of your project (this can be changes in the Run Configuration/Arguments/Working Directory). So the file in the "src" directory will not be found, unless you either:

  • Use "src/robot.properties" instead of "robot.properties"
  • or use the file's full path
  • or use a ResourceBundle to read your properties file and put your file in the classpath


  • [My Blog]
    All roads lead to JavaRanch
    sarada bokka
    Ranch Hand

    Joined: Jan 13, 2010
    Posts: 80
    full path works fine i am able to get the properties file
    but

    If i do any modification in my project .Eclipse is unable to built/clear project again and throws error. It built only the files available in the path of properties file
    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14688
        
      16

    throws error

    What error ? Can you post the error message ?
    sarada bokka
    Ranch Hand

    Joined: Jan 13, 2010
    Posts: 80
    Caused by: java.lang.ClassNotFoundException: com.robot.Main

    because it is unable to compile the classes any more .

    1) I always need to delete the bin directory and then recompile when ever i modified my code.

    When ever i modify the code and try to build .It just put only the properties file in the bin so i must repeat the step 1) for each modification i done.
    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14688
        
      16

    because it is unable to compile the classes any more .

    Why ? Did you check Project/Build Automatically ? Isn't there any error displayed ? If none, can you check if there are errors in the following file ${ECLIPSE_HOME}/workspace/.metadata/.log ?
    sarada bokka
    Ranch Hand

    Joined: Jan 13, 2010
    Posts: 80
    Yes,build automatic was checked.

    One more thing this happens only if i do modification on property file else every thing works fine.

    error in .log

    !ENTRY org.eclipse.jdt.core 4 4 2010-04-15 16:57:12.937
    !MESSAGE JavaBuilder handling ImageBuilderInternalException while building: Robot
    !STACK 1
    org.eclipse.core.internal.resources.ResourceException: Problems encountered while deleting resources.
    at org.eclipse.core.internal.resources.Resource.delete(Resource.java:724)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:659)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:522)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:522)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:522)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:473)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:92)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:633)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
    Contains: Could not delete 'C:\Eclipse\MyProjects\Robot\bin\com\robot\util\robot.properties'.
    !SUBENTRY 1 org.eclipse.core.resources 4 273 2010-04-15 16:57:12.937
    !MESSAGE Problems encountered while deleting resources.
    !SUBENTRY 2 org.eclipse.core.resources 4 273 2010-04-15 16:57:12.937
    !MESSAGE Could not delete 'C:\Eclipse\MyProjects\Robot\bin\com\robot\util\robot.properties'.
    !STACK 1
    org.eclipse.core.runtime.CoreException: Problems encountered while deleting files.
    at org.eclipse.core.internal.filesystem.local.LocalFile.delete(LocalFile.java:123)
    at org.eclipse.core.internal.resources.ResourceTree.internalDeleteFile(ResourceTree.java:302)
    at org.eclipse.core.internal.resources.ResourceTree.standardDeleteFile(ResourceTree.java:779)
    at org.eclipse.core.internal.resources.Resource.unprotectedDelete(Resource.java:1720)
    at org.eclipse.core.internal.resources.Resource.delete(Resource.java:711)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:659)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:522)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:522)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:522)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IncrementalImageBuilder.java:473)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:92)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:633)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
    Contains: Could not delete: C:\Eclipse\MyProjects\Robot\bin\com\robot\util\robot.properties.
    !SUBENTRY 3 org.eclipse.core.filesystem 4 273 2010-04-15 16:57:12.937
    !MESSAGE Problems encountered while deleting files.
    !SUBENTRY 4 org.eclipse.core.filesystem 4 273 2010-04-15 16:57:12.937
    !MESSAGE Could not delete: C:\Eclipse\MyProjects\Robot\bin\com\robot\util\robot.properties.
    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14688
        
      16

    Make sure you're not editing the file under "bin". Edit the one under "src". If you're not, the easiest way to avoid this would be to put your properties file in a different folder, not under "src".
    sarada bokka
    Ranch Hand

    Joined: Jan 13, 2010
    Posts: 80
    I am not editing the file under bin.

    The problem was solved by placing in a different folder, not under "src"

    Thank you so much Christophe
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Unable to load properties file in Java using eclipse