Always remember that Maven’s policy is convention over configuration
.
That being said, in your case, while using Maven, you need to follow the Maven Standard Directory Structure.
Create a directory structure like src/main/java
and put your package(s) in the java
folder.
For any resources, create a folder structure like src/main/resources
and put your resources in the resources
folder.
After you do this, lets say that there is a file named readme.txt inside src/main/resources
directory, then you can simple access this file using:File file = new File("readme.txt");
Maven will always treat src/main/resources
as the root for any resources.
Another example is lets say you have a a file name hello.txt in src/main/resources/somefolder/hello.txt
then you can access it using:File file = new File("somefolder/readme.txt");
solved Java Maven reference files in WebApp