1

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?

Jerrin Thomas
  • 269
  • 3
  • 14

3 Answers3

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.