I am creating a Java Application where in I need to read templates which I am not able to. That is because I am not able to locate the files with proper path.
The code structure is as follows:
The template reading class file is in src/main/java/com.prototype.main while, The templates are residing in src/main/java/templates
Which means, when I create a jar the three folders would be 3 folders: com templates META-INF
Now from any class under the package how can I access the templates? I have tried the following:
- new File("/") which in case of web application would have picked from the root directory of the application but in stand alone applications it is the user directory of the system
- System.getProperty("user.dir") which gives the project directory
- new App().getClass().getName() which shows the package name separated by dot
So if I want to read a template file like /templates/some.xml, how do I get the entire path of this file?
Thanks for any help in advance.