Project root folder path

20,855

Turns out Eclipse puts the entire content of the res folder in the root folder of the bin folder. Therefore the path is just very simply /file.xml. I tried putting it into a subfolder of res called xmls and the path then is /xmls/file.xml

I also went to the source tab of the java build path and added the res folder.

Share:
20,855
Killerpixler
Author by

Killerpixler

Updated on October 22, 2020

Comments

  • Killerpixler
    Killerpixler over 3 years

    I have a class in a package com.mwerner.utils that needs the path for an getResourceAsStream() call

    the file it is supposed to load is located in a subfolder of the project root i.e.:

    /src/com/mwerner/utils/myfile.java has to load

    /res/file.xml

    I tried stuff like

    /res/file.xml
    ../res/file.xml
    res/file.xml
    

    What is the right one?

    EDIT:

    I am using Xstream to parse the XML into objects. The line of code in question is:

    ObjectInputStream in = xstream.createObjectInputStream(Utils.class.getResourceAsStream("res/file.xml"));
    

    I get an IOException with unknown source

    • Daniel
      Daniel over 10 years
      I dont't know how the code is executed, but try to add these lines Path currentRelativePath = Paths.get(""); String s = currentRelativePath.toAbsolutePath().toString(); System.out.println("Current relative path is: " + s); This should print out the current folder
    • Behe
      Behe over 10 years
      What did you try and what happened?
    • Viktor Seifert
      Viktor Seifert over 10 years
      So the 'src' and 'res' directories are located in the same parent directory?
    • Killerpixler
      Killerpixler over 10 years
      well the src folder is where eclipse stores the source code, the res folder is - like the src folder - in the root of the project, i.e. would be in the root of the JAR that i'd package for distribution