Assume standard maven setup. I have a file abc.conf in src/main/resources folder of my project. How do i get the absolute path to abc.conf in the code?
Asked
Active
Viewed 2,885 times
1
-
Check this link : https://stackoverflow.com/questions/15749192/how-do-i-load-a-file-from-resource-folder – Harry Coder Nov 27 '19 at 02:52
3 Answers
1
You'll be able to elicit the path of the resource in the JAR, but the running program can't know, where your development repository is, unless you supply the information explicitly.

Curiosa Globunznik
- 3,129
- 1
- 16
- 24
1
When you run your app, you are not using the resource file in your code folder(src/main/resources) but the ones in the target folder([yourProject]\target as default) where you build to.The target folder path can be changed, it's not a absolute path.
So you can use a "absolute" path out of the content you run or use a "relative" path to the target folder.

ender1986
- 95
- 1
- 9
0
Maven automatically sets the current working directory, then you can just use:
File resourcesDirectory = new File("src/main/resources/abc.conf");
System.out.println( resourcesDirectory.getAbsolutePath() ); //prints absolute path of your abc.conf
I hope it helps.

Grégori Fernandes de Lima
- 1,226
- 11
- 13