How to locate the Path of the current project directory in Java (IDE)?

前端 未结 9 1403
梦如初夏
梦如初夏 2020-11-28 21:46

I am trying to locate the path of the current running/debugged project programmatically in Java, I looked in Google and what I found was System.getProperty(\"user.id\"

9条回答
  •  旧时难觅i
    2020-11-28 22:15

    YOU CANT.

    Java-Projects does not have ONE path! Java-Projects has multiple pathes even so one Class can have multiple locations in different classpath's in one "Project".

    So if you have a calculator.jar located in your JRE/lib and one calculator.jar with the same classes on a CD: if you execute the calculator.jar the classes from the CD, the java-vm will take the classes from the JRE/lib!

    This problem often comes to programmers who like to load resources deployed inside of the Project. In this case,

    System.getResource("/likebutton.png") 
    

    is taken for example.

提交回复
热议问题